Model Utilities

load_mltk_model

load_mltk_model(model, test=False, print_not_found_err=False, logger=None, reload=True)[source]

Find a MLTK model with the given name and instantiate its corresponding mltk.core.MltkModel object

Parameters:
  • model (str) – Name of MLTK model or path to MLTK model’s python specification script or archive. Append -test to the MLTK model name to load into “testing” mode (this is the same as setting the argument: test=True)

  • test (bool) – If the MLTK model should be loaded in “testing” mode

  • print_not_found_err – If true and the MLTK model is not found, then print an error

  • reload (bool) – If the given model is a python script then reload the module if necessary

  • logger (Logger) –

Return type:

MltkModel

Returns:

Load model object

load_mltk_model_with_path

load_mltk_model_with_path(model_path, test=False, logger=None, reload=True)[source]

Instantiate a MltkModel object from the given model path The model path can be a .py model specificaton or a model archive .mltk.zip.

Return type:

MltkModel

Parameters:
  • model_path (str) –

  • test (bool) –

  • logger (Logger) –

  • reload (bool) –

list_mltk_models

list_mltk_models(test=False, for_utests=False, logger=None)[source]

Return a list of all found MLTK model names

Return type:

List[str]

Parameters:
  • test (bool) –

  • logger (Logger) –

load_tflite_or_keras_model

load_tflite_or_keras_model(model, model_type=None, weights=None, logger=None)[source]

Instantiate a Keras or TfliteModel object

IF model is an mltk.core.MltkModel instance OR a model archive .mltk.zip, AND model_type is:

ELSE model should be the file path to a .tflite or .h5 model file.

Return type:

Union[TfliteModel, Model]

Parameters:
  • model (Union[MltkModel, str]) –

  • model_type (str) –

  • weights (str) –

  • logger (Logger) –

load_tflite_model

load_tflite_model(model, build=False, print_not_found_err=False, return_tflite_path=False, test=False, logger=None, archive_file_ext=None)[source]

Return the path to a .tflite model file or a TfliteModel instance

Parameters:
  • model (Union[str, MltkModel, TfliteModel]) – One of the following: - An MltkModel model instance - An TfliteModel model instance - The path to a .tflite - The path to a .mltk.zip model archive - The path to a .py MLTK model specification - The name of an MLTK model

  • build (bool) – If the given Mltk model should be built into a .tflite

  • print_not_found_err (bool) – If the model model is not found, print possible alternatives and exit

  • return_tflite_path (bool) – If true, return the file path to the .tflite, otherwise return a TfliteModel instance

  • test (bool) – If a “test” model is provided

  • logger (Logger) – Optional logger

  • archive_file_ext (str) – The extension of the .tflite model file in the mltk archive, e.g. .streaming.tflite This is only used if the “model” argument is the path to a .mltk.zip, the path to a .py MLTK model specification, or the name of an MLTK model

Return type:

Union[TfliteModel, str]

Returns:

The corresponding TfliteModel if return_tflite_path=False or the path to the .tflite if return_tflite_path=True