Managing Models

Once deployed, Fritz allows you to manage your models across live devices. You can provide new, updated, versions of your model and automatically deploy them to users. You don’t need to create a new version of your app, or go through an app store release process.

Adding a New Model Version

Start by adding your new model version.

Navigate to Custom Models and select your model, in this example scenario we’re using a handwriting recognition model.

Upload your new model version:

Adding an updated model

Adding an updated model (click image to view full size)

After the upload completes your new model will appear in the model versions table. Note: Uploading a new model version does not make it active. To make a new version active, see the Releasing section below.

Releasing a New Model Version

After you’ve added the new model version (above), you can set the new model to active. This will begin a release. Devices using your model will download the updated model version when they are connected to WiFi, and switch over to it. Model updates, and downloads, occur in the background and no user input is required.

Update active version:

Updating active model version

Updating active model version (click image to view full size)

You can monitor the usage of the new model version on the Dashboard. The new model version will be an option in the top dashboard filters section. Both active and inactive versions are viewable.

Adding Tags to Models

Add tags to your custom models to dynamically control which models users see.

Add tags on the Model Details page in the webapp. Here we are adding two tags, handwriting-model and digits:

Adding model tags

Adding model tags (click image to view full size)

Tags can be added or removed from individual models and are global per across the project.

Querying Tags in the iOS SDK

After adding tags to models, you can query tags in the iOS SDK.

1. Create a ModelTagManager instance:

import Fritz

let tagManager = ModelTagManager(tags: ["handwriting-model", "digits"])

2. Fetch list of FritzManagedModel from the API:

Results will contain models that match all tags. Thus, tag queries for the above tagManager will match models that contain both handwriting-model and digits.

tagManager.fetchManagedModelsForTags { managedModels, error in
  guard let fritzManagedModels = managedModels, error == nil else {
    return
  }
}

The result of the tag query (when successful) is a FritzManagedModel list. These are not instantiated models. They contain the configuration of models stored in Fritz. You can download them as needed.

3. Download models from API:

Using the FritzManagedModel list from the previous query, you can download the models and instantiate the MLModel:

var allModels: [FritzMLModel] = []

tagManager.fetchManagedModelsForTags { managedModels, error in
    guard let fritzManagedModels = managedModels, error == nil else {
        return
    }

    for managedModel in fritzManagedModels {
        managedModel.fetchModel { downloadedModel, error in
            guard let fritzMLModel = downloadedModel, error == nil else {
                return
            }

            allModels.append(fritzMLModel)
        }
  }

Once the model is downloaded the first time, calling managedModel.fetchModel again will load that model from disk.

Note

Depending on the size of your model, you may want to force downloads to happen over WiFi. To do so, set wifiRequiredForModelDownload to true. By default, all models will download over both WiFi and cellular connections:

tagManager.fetchManagedModelsForTags(wifiRequiredForModelDownload: true) { managedModels, error in
  // ...
}

let fritzManagedModels = tagManager.getManagedModelsForTags(wifiRequiredForModelDownload: true)

All tag requests are cached and stored locally. If you wish to query locally cached models, you can call getManagedModelsForTags:

let fritzManagedModels = tagManager.getManagedModelsForTags()

for managedModel in fritzManagedModels {
    managedModel.fetchModel { downloadedModel, error in
        guard let fritzMLModel = downloadedModel, error == nil else {
            return
        }
        allModels.append(fritzMLModel)
    }
}

Adding Metadata to Models

You can add metadata to any custom model. This metadata is accessible via the SDK. Examples of metadata include a pretty name to be shown to users or a link to a thumbnail image. All entered keys and values are stored as strings.

Adding model metadata

Adding model metadata (click image to view full size)

Model metadata must fit the following requirements:

  • No more than 20 key-value pairs.
  • Keys must be no longer than 40 characters.
  • Values must be no longer than 500 characters.