Fritz Python Library

Fritz is a library to simplify your mobile machine learning workflow.

usage:
>>> import fritz
>>> client = fritz.client.FritzClient('<your api key>')
>>> model_details = client.upload_new_model_version(
        '<model_uid>', '/path/to/your_great_model.mlmodel'
    )
>>> print(model_details)
{
    'model': {'uid': '<model_uid>', ...}
    'version': {'uid': '<version_uid>', ...}
}
copyright:© 2018 by Fritz Labs Incorporated
license:MIT, see LICENSE for more details.

fritz.keras.model_checkpoint

This module contains a Keras callback to upload new versions of a model to Fritz.

class fritz.keras.model_checkpoint.FritzMLModelCheckpoint(fritz_api_key, model_uid, keras_filename, convert_function, period=1, deploy=False)

Saves current Keras model as a new MLModel in Fritz.

Save a checkpoint to Fritz.

Parameters:
  • fritz_api_key (str) – Fritz client API key.
  • model_uid (str) – Fritz Model UID to add new versions to.
  • keras_filename (str) – Name of Keras model output filename.
  • convert_function (func) – Function used to convert Keras model to mobile model.
  • period (int) – Interval (number of epochs) between checkpoints.
  • deploy (bool) – If True will set active version of model to latest uploaded model. Default False.

add_model_metadata(logs)

Adds additional metadata about the model to be stored in Fritz.

Optionally override this method returning custom information.

Parameters:logs (dict) – Includes values such as acc and loss.

Returns: Dict of model metadata.

on_epoch_end(epoch, logs=None)

Saves model to Fritz on epoch end.

Parameters:
  • epoch (int) – the epoch number
  • logs (dict, optional) – logs dict

on_train_end(logs=None)

Saves model to Fritz at end of training run.

Parameters:
  • epoch (int) – the epoch number
  • logs (dict, optional) – logs dict

class fritz.keras.model_checkpoint.FritzTFLiteModelCheckpoint(fritz_api_key, model_uid, keras_filename, convert_function, period=1, deploy=False)

Saves current Keras model as a new TensorFlow Lite model in Fritz.

Save a checkpoint to Fritz.

Parameters:
  • fritz_api_key (str) – Fritz client API key.
  • model_uid (str) – Fritz Model UID to add new versions to.
  • keras_filename (str) – Name of Keras model output filename.
  • convert_function (func) – Function used to convert Keras model to mobile model.
  • period (int) – Interval (number of epochs) between checkpoints.
  • deploy (bool) – If True will set active version of model to latest uploaded model. Default False.

add_model_metadata(logs)

Adds additional metadata about the model to be stored in Fritz.

Optionally override this method returning custom information.

Parameters:logs (dict) – Includes values such as acc and loss.

Returns: Dict of model metadata.

on_epoch_end(epoch, logs=None)

Saves model to Fritz on epoch end.

Parameters:
  • epoch (int) – the epoch number
  • logs (dict, optional) – logs dict

on_train_end(logs=None)

Saves model to Fritz at end of training run.

Parameters:
  • epoch (int) – the epoch number
  • logs (dict, optional) – logs dict

class fritz.keras.model_checkpoint.FritzTFMobileModelCheckpoint(fritz_api_key, model_uid, keras_filename, convert_function, period=1, deploy=False)

Saves current Keras model as a new TensorFlow Mobile model in Fritz.

Save a checkpoint to Fritz.

Parameters:
  • fritz_api_key (str) – Fritz client API key.
  • model_uid (str) – Fritz Model UID to add new versions to.
  • keras_filename (str) – Name of Keras model output filename.
  • convert_function (func) – Function used to convert Keras model to mobile model.
  • period (int) – Interval (number of epochs) between checkpoints.
  • deploy (bool) – If True will set active version of model to latest uploaded model. Default False.

add_model_metadata(logs)

Adds additional metadata about the model to be stored in Fritz.

Optionally override this method returning custom information.

Parameters:logs (dict) – Includes values such as acc and loss.

Returns: Dict of model metadata.

on_epoch_end(epoch, logs=None)

Saves model to Fritz on epoch end.

Parameters:
  • epoch (int) – the epoch number
  • logs (dict, optional) – logs dict

on_train_end(logs=None)

Saves model to Fritz at end of training run.

Parameters:
  • epoch (int) – the epoch number
  • logs (dict, optional) – logs dict

fritz.client.api_client

This module contains the FritzClient for interacting with the Fritz API.

class fritz.client.api_client.FritzClient(api_key)

Client used to interact with the Fritz API.

**API_PATH**\  = 'https://api.fritz.ai'

class fritz.client.api_client.FritzClientBase(api_key, base_url)

Fritz Client to interact with Fritz API.

Parameters:
  • api_key (str) – Account API Key for Fritz API.
  • base_url (str) – URL base of Fritz API.

upload_new_version(model_uid, uploaded_model_name, model, set_active=False, metadata=None)

Upload new version of a model from an instantiated model in memory.

Use to upload new versions of Core ML, TensorFlow Lite, or TensorFlow Mobile models. You can choose if you want to deploy the model to all devices or just upload to the webapp.

If you are using a TensorFlow Lite model, make sure that the model is the output from the converter. This should be a bytes object of a flat buffer.

Parameters:
  • model_uid (str) – Model Identifier to update.
  • uploaded_model_name (str) – Name of model to save (must contain model extension, e.g. mymodel.mlmodel).
  • model (Union[coremltools.models.MLModel, bytes]) – Model file to upload. Must be an instantiated Core ML, TensorFlow Lite, or TensorFlow Mobile model.
  • set_active (bool) – If True, will set active version of model to newly uploaded model.
  • metadata (Dict) – Dictionary of JSON serializable metadata about model.

Returns: Model and ModelVersion of uploaded model.

Raises:ValueErrormodel_name does not have the correct extension or model is not the correct type.

upload_new_version_from_file(model_uid, model_path, set_active=False, metadata=None)

Upload new version of a model from a model stored on disk.

Use to upload new versions of Core ML, TensorFlow Lite, or TensorFlow Mobile models. Can choose if you want to deploy the model to all devices or just upload to the webapp.

Parameters:
  • model_uid (str) – Model Identifier to update.
  • model_path (str) – Path to saved model. If model is not provided, model will be loaded from this path. Must be a Core ML, TensorFlow Lite, or TensorFlow Mobile model.
  • set_active (bool) – If True, will set active version of model to newly uploaded model.
  • metadata (Dict) – Dictionary of JSON serializable metadata about model.

Returns: Model and ModelVersion of uploaded model.

Raises: ValueError if model_path does not have a valid extension.