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:

mltk.core.MltkModel

The root MLTK Model object

mltk.core.TrainMixin

Provides training properties and methods to the base MltkModel

mltk.core.DatasetMixin

Provides generic dataset properties to the base MltkModel

mltk.core.AudioDatasetMixin

Provides audio dataset properties to the base MltkModel

mltk.core.ImageDatasetMixin

Provides image dataset properties to the base MltkModel

mltk.core.EvaluateMixin

Provides generic evaluation properties and methods to the base MltkModel

mltk.core.EvaluateAutoEncoderMixin

Provides evaluation properties and methods to the base MltkModel

mltk.core.EvaluateClassifierMixin

Provides evaluation properties and methods to the base MltkModel

mltk.core.SshMixin

Provides various properties to the base MltkModel used by the ssh MLTK command.

mltk.core.WeightsAndBiasesMixin

Provides various properties to the base MltkModel used by Weights & Biases 3rd-party cloud backend.

mltk.core.MltkDataset

Helper class for configuring a training dataset

mltk.core.MltkModelEvent

Events that are triggered at various stages of MltkModel execution.