Train and Deploy Custom Models

Use our custom Keras callback class to reduce the number of steps needed to test out the latest version of a model in your mobile app. The FritzSnapshotCallback helps upload and convert mobile models as you train your model.

Create converter functions to convert Keras model to Mobile Frameworks

Build converter functions for each mobile framework you wish to use. Each converter function should return an instance of that framework's model:

Core ML

You will most likely use the coremltools library from Apple.

If you are unsure how to convert the model, the coremltools documentation can help you get started.

Here is an example on how to convert the Image Segmentation model available Image Segmentation Model:

import coremltools
def convert_model_to_coreml(model):
return coremltools.converters.keras.convert(
image_scale=1.0 / 255.0,

Configure the FritzSnapshotCallback

Next, you will configure the FritzSnapshotCallback with the converters you wish to use for training.

import fritz
import fritz.keras
def keras_to_core_ml(keras_model):
"""Function that converts converted MLModel"""
converters = {
fritz.frameworks.CORE_ML: keras_to_core_ml
KERAS_MODEL_FILENAME = "/path/to/keras_model.h5"
callback = fritz.keras.FritzSnapshotCallback(

You can configure the following parameters for the FritzSnapshotCallback:

FritzSnapshotCallback options

output_file_name (Required)
Output file name of saved Keras model.
model_uids_by_frameworkNone (default)
Dictionary mapping model framework to model uids. If model_uid not set for a given platform, a new model will be created.
converters_by_frameworkNone (default)
Dictionary mapping model framework to conversion function.
period10 (default)
Interval (number of epochs) between uploading new versions of models.
deployFalse (default)
If True, will update the active version to the newly uploaded models.
api_keyNone (default)
Optional API Key which overrides the globally set value
project_uidNone (default)
Optional Project UID which overrides the globally set value.

Connecting to existing Fritz AI models

Specify the Model ID

If you already have a model in Fritz AI that you wish to update you can specify which model to update:

model_ids = {
fritz.frameworks.CORE_ML: "<Model UID for Core ML Model>"
callback = fritz.keras.FritzSnapshotCallback(

When the callback runs, it will upload models to the specified model ID.

Use an existing model name

Alternatively, if you do not specify a Model ID, Fritz AI will look for models with the same name as the filename.

Re-training a model used in a production app

If you are re-training a model deployed in a production app, you may want to test out a model as it is being retrained without deploying the model to all users. In this case, we strongly recommend you create a new development version of the model in the webapp. Here are the basic steps:

  1. Create a new model development model from the Models page using the current version of the model.
  2. Update the modelIdentifier in your local development app with the model identifier of the newly created model.
  3. Create a FritzSnapshotCallback callback specifying the Model ID:
model_ids = {
fritz.frameworks.CORE_ML: "<Model ID of development model>"
callback = fritz.keras.FritzSnapshotCallback(
  1. Begin training the model. During training, your local development app will update, but production apps will not be affected.
  2. After you have finished training and wish to deploy model to all users, download the model version and add as a new version in the webapp.
  3. To deploy this update to all devices, set the active version to the latest uploaded version from the Model Details page in the webapp.
  4. If you are done using the development model, archive it from the Model Details page so it does not show up in your active model list.