MLTK Model¶
The MltkModel is the root object used to create a model specification.
The model specification should define an object that inherits MltkModel and any other required mixins. Once the object is defined and instantiated, the various properties should be populated. After the model specification is finished, it may be invoked with one of the various Model Operations.
Example Usage¶
The following is a snippet from the basic_example reference model:
import mltk.core as mltk_core
class MyModel(
mltk_core.MltkModel, # We must inherit the MltkModel class
mltk_core.TrainMixin, # We also inherit the TrainMixin since we want to train this model
mltk_core.DatasetMixin, # We also need the DatasetMixin mixin to provide the relevant dataset properties
mltk_core.EvaluateClassifierMixin, # While not required, also inherit EvaluateClassifierMixin to help will generating evaluation for our classification model
):
pass
my_model = MyModel()
my_model.version = 1
my_model.description = 'Basic model specification example'
my_model.classes = ['cat', 'dog', 'goat']
my_model.class_weights = 'balanced'
my_model.batch_size = 32
my_model.epochs = 100
my_model.validation_split = 0.2
...
if __name__ == '__main__':
# Train the model
# This does the same as issuing the command: mltk train basic_example
mltk_core.train_model(my_model, clean=True)
# Evaluate the model against the quantized .tflite (i.e. int8) model
# This does the same as issuing the command: mltk evaluate basic_example --tflite
mltk_core.evaluate_model(my_model, tflite=True)
# Profile the model in the simulator
# This does the same as issuing the command: mltk profile basic_example
mltk_core.profile_model(my_model)
See the reference models for more examples.
Additional Model Utilities are also available.
API Reference¶
The following MltkModel mixins are available:
The root MLTK Model object |
Provides training properties and methods to the base |
Provides generic dataset properties to the base |
Provides audio dataset properties to the base |
Provides image dataset properties to the base |
Provides generic evaluation properties and methods to the base |
Provides evaluation properties and methods to the base |
Provides evaluation properties and methods to the base |
Provides various properties to the base |
Provides various properties to the base |
Helper class for configuring a training dataset |
Events that are triggered at various stages of |