Using Model Update in applications
With the introduction of on-device machine learning (ML) models such as CoreML and TensorFlow Lite, mobile apps can now perform ML operations such as image recognition, speech to text etc., on the device even when the device is offline. An important characteristic of a machine learning model is that they continuously evolve. Updating these models with their newer versions, on a device, becomes extremely critical to the success of a mobile app.
To assist with this requirement, IBM Mobile Foundation introduces the Model Update feature. Mobile Foundation applications can now embed ML models, which can be updated “over-the-air” with newer versions. Organizations are thus able to ensure that end-users always use the updated AI models.
Compress the latest model(s) into a zip format, in order to send the model version to an application. This
.zip needs to be uploaded under the Machine Learning tab of the MobileFirst Operations console. Model Update is then activated whenever the application invokes
Supported platforms: Currently, Model Update is supported only for iOS.
Points to note
- Model Update updates only the Artificial Intelligence models like Apple’s CoreML Model or Google’s TensorFlow Model.
How Model Update works
The models are initially packaged with the application to ensure first offline availability. Later, the application checks for updates with the MobileFirst Server whenever the
downloadModelUpdate API is invoked.
After a Model Update,
downloadModelUpdate API returns the location of the downloaded model and this location gets updated whenever an update is performed.
A Model Update applies only to a specific application version. In other words, updates generated for an application versioned 2.0 cannot be applied to a different version of the same application.
Creating and deploying model packages
When a newer or updated version of the model is available, follow the steps below to upload the model file to the MobileFirst Server.
- Create an
.ziparchive of one or more machine learning model files (e.g.
- Open the MobileFirst Operations Console and click the application entry in the left panel.
- Navigate to Machine Learning tab and click Upload model archive to upload the packaged models.
Invoking an update
Model update in the application can be checked by invoking the following API.
WLClient.sharedInstance().downloadModelUpdate(completionHandler: CompletionHandler, showProgressBar: Boolean);
Note: This API shouldn’t be invoked simultaneously with
Typically, application developers should call this API during the startup of the application.
downloadModelUpdate API returns one of the following status codes and a link to the downloaded package, if the download is successful, or the path to the previously downloaded package is returned.
The final status will be one of the following codes:
||Model update finished with no errors.|
||Model update was canceled.|
||There was a problem with a network connection during the update.|
||The file was not downloaded completely.|
||There is not enough space on the device to download and unpack the update file.|
||There was a problem unpacking the update file.|
||An update was requested when one was already in progress.|
||Authenticity of update file cannot be verified.|
||Unexpected internal error.|
Secure Model Update
Disabled by default, Secure Model Update prevents a third-party attacker from altering the models that are transferred from the MobileFirst Server (or from a Content Delivery Network (CDN)) to the client application.
To enable Model Update authenticity
Using a preferred tool, extract the public key from the MobileFirst Server keystore and convert it to base64.
The produced value should then be used as below:
- In the client application, open the mobilefirst configuration file (i.e
mfpclient.plistfor iOS and
- Add the new key value called
- Provide the public key for the corresponding key value and save.
Any future Model Update deliveries to client applications will be protected by Model Update authenticity.
To configure the application server with the updated keystore file, see Implementing secure Model Update
Model Update in development, testing, and production
For development and testing purposes, developers typically use Model Update by simply uploading an archive to the development server. While this process is easy to implement, it is not very secure as models can be tampered either during transit or after being downloaded on the device.
For the production or even pre-production testing phase, it is strongly recommended to implement secure Model Update before you publish your application to the app store. Secure Model Update requires an RSA key pair that is extracted from a CA signed server certificate.
Note: Take care that you do not modify the keystore configuration after the application was published, updates that are downloaded can no longer be authenticated without reconfiguring the application with a new public key and republishing the application. Without performing these steps, Model Update fails on the client.
Learn more in Secure Model Update.
Model Update data transfer rates
At optimal conditions, a single MobileFirst Server can push data to clients at the rate of 250 MB per second. If higher rates are required, consider a cluster or a CDN service.▲