train_model

train_model(model, weights=None, epochs=None, resume_epoch=0, verbose=None, clean=False, quantize=True, create_archive=True, show=False, test=False, post_process=False)[source]

Train a model using Keras and Tensorflow

Parameters:
  • model (Union[MltkModel, str]) – mltk.core.MltkModel instance, name of MLTK model, path to model specification script(.py) __Note:__ If the model is in “test mode” then the model will train for 1 epoch

  • weights (str) – Optional file path of model weights to load before training

  • epochs (int) – Optional, number of epochs to train model. This overrides the mltk_model.epochs attribute

  • resume_epoch (int) – Optional, resuming training at the given epoch

  • verbose (bool) – Optional, Verbosely print to logger while training

  • clean (bool) – Optional, Clean the log directory before training

  • quantize (bool) – Optional, quantize the model after training successfully completes

  • create_archive (bool) – Optional, create an archive (.mltk.zip) of the training results and generated model files

  • show (bool) – Optional, show the training results diagram

  • test (bool) – Optional, load the model in “test mode” if true.

  • post_process (bool) – This allows for post-processing the training results (e.g. uploading to a cloud) if supported by the given MltkModel

Return type:

TrainingResults

Returns:

The model TrainingResults

TrainingResults

class TrainingResults[source]

Container for the model training results

__init__(mltk_model, keras_model, training_history)[source]
Parameters:

keras_model (Model) –

mltk_model

The MltkModel uses for training

keras_model: Model

The trained KerasModel

epochs: List[int]

List of integers corresponding to each epoch

params: dict

Dictionary of parameters uses for training

history

Dictionary of metrics recorded for each epoch

property model_archive_path: str

File path to model archive which contains the model training output including trained model file

Return type:

str

asdict()[source]

Return the results as a dictionary

Return type:

dict

get_best_metric()[source]

Return the best metric from training

Return type:

Tuple[str, float]

Returns:

Tuple(Name of metric, best metric value)