pimlico.datatypes.keras module¶
Datatypes for storing and loading Keras models.
-
class
KerasModelWriter
(base_dir, **kwargs)[source]¶ Bases:
pimlico.datatypes.base.PimlicoDatatypeWriter
Writer for storing both types of Keras model (since they provide the same storage interface).
-
class
KerasModel
(base_dir, pipeline, module=None, additional_name=None, use_main_metadata=False, **kwargs)[source]¶ Bases:
pimlico.datatypes.base.PimlicoDatatype
Datatype for both types of Keras models, stored using Keras’ own storage mechanisms. This uses Keras’ method of storing the model architecture as JSON and stores the weights using hdf5.
-
datatype_name
= 'keras_model'¶
-
custom_objects
= {}¶
-
-
class
KerasModelBuilderClassWriter
(base_dir, build_params, builder_class_path, **kwargs)[source]¶ Bases:
pimlico.datatypes.base.PimlicoDatatypeWriter
Writer for storing Keras models in the manner described in :cls:KerasModelBuilderClass.
-
class
KerasModelBuilderClass
(base_dir, pipeline, **kwargs)[source]¶ Bases:
pimlico.datatypes.base.PimlicoDatatype
An alternative way to store Keras models.
Create a class whose init method build the model architecture. It should take a kwarg called build_params, which is a JSON-encodable dictionary of parameters that determine how the model gets build (hyperparameters). When you initialize your model for training, create this hyperparameter dictionary and use it to instantiate the model class.
Use the KerasModelBuilderClassWriter to store the model during training. Create a writer, then start model training, storing the weights to the filename given by the weights_filename attribute of the writer. The hyperparameter dictionary will also be stored.
The writer also stores the fully-qualified path of the model-builder class. When we read the datatype and want to rebuild the model, we import the class, instantiate it and then set its weights to those we’ve stored.
The model builder class must have the model stored in an attribute model.
-
weights_filename
¶
-