Tag-based Model Distribution

Only available on Growth plans

For more information on plans and pricing, visit our website.

Add tags and metadata to on-device machine learning models. Models can be queried by tags and loaded dynamically via the SDK giving you more control over distribution and usage. Deliver models to users based on hardware, location, software environment or any other attribute.

Adding Tags

Add tags to your 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:

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

Adding Metadata

You can add metadata to any 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.

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.

Distribute Models By Tag (iOS)

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:

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 a FritzManagedModel:

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)
}
}

Distribute Models By Tag (Android)

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

1. Fetch a list of FritzManagedModels:

Fritz.fetchManagedModelsByTags(new String[]{"group-1"}, new SearchModelTagsListener() {
@Override
public void onCompleted(List<FritzManagedModel> modelVersions) {
// do something with the managed models
}
@Override
public void onError() {
// handle errors with the API
}
});

2. Download a FritzManagedModel:

// Models will be downloaded one at a time and stored on the device.
Fritz.loadOnDeviceModelsByTags(new String[]{"group-1", "group-2"}, new DownloadTaggedModelsListener() {
@Override
public void onCompleted(List<FritzOnDeviceModel> onDeviceModels) {
Log.d(TAG, "READY TO USE MODELS: " + onDeviceModels.size());
// From here, you can create interpreters for your models when you're ready to use them.
FritzOnDeviceModel onDeviceModel = onDeviceModels.get(0);
FritzTFLiteInterpreter interpreter = new FritzTFLiteInterpreter(onDeviceModel);
}
@Override
public void onError() {
Log.e(TAG, "Something went wrong loading the models");
}
});