Sub topic 14
Packaging, Delivering, and Updating Vision Models
Assume you know tensors, image preprocessing, and at least one mobile inference runtime such as TensorFlow Lite or ONNX Runtime. This chapter focuses on the release process after a model has been converted and tested.
Package the model as a versioned bundle
A model file is only one part of a working feature. The app also needs the information required to prepare inputs and interpret outputs. Package these files together:
- The model file, such as an ONNX or TensorFlow Lite file.
- A manifest containing the model version, format, input shape, data type, and minimum app version.
- Class labels or other output metadata.
- Preprocessing settings, including image size, color order, scaling, and normalization.
- A cryptographic hash for each file.
- Optional calibration, license, and release notes.
Use immutable versions. For example, name a release 2.3.0 rather than replacing a file called latest.tflite. Immutable files make caching, rollback, and debugging predictable.
| Bundle item | Purpose |
|---|---|
| Model file | Performs inference |
| Manifest | Describes compatibility and contents |
| Labels | Maps output indices to user-visible classes |
| Hash | Detects accidental or incomplete downloads |
A manifest might look like this:
{
"model_version": "2.3.0",
"format": "tflite",
"input": {
"shape": [1, 224, 224, 3],
"dtype": "uint8",
"color_order": "RGB"
},
"minimum_app_version": "5.1.0",
"model_sha256": "..."
}Keep preprocessing metadata tied to the model version. A model trained with values normalized to a different range can produce incorrect predictions even when inference succeeds.
Deliver models safely
For small, stable models, bundle the model inside the application. This makes the first run reliable and allows the app store to distribute the model. The trade-off is a larger application and slower model updates.
For larger or frequently updated models, download a bundle from a server. The app should:
- Download the manifest over authenticated HTTPS.
- Check that the model is compatible with the installed app and device.
- Download the model to a temporary path.
- Verify its size and cryptographic hash.
- Load-test the model before activation.
- Rename or move it atomically into the active-model location.
- Retain the previous working version for rollback.
A hash detects corruption, but it does not by itself prove who published the file. For stronger protection, sign the manifest and verify the signature with a public key embedded in the app. Keep private signing keys outside the application and build machines used by ordinary developers.
Roll out and roll back updates
Treat a model release like a software release. Start with internal testers, then use a staged rollout. Monitor crash rates, prediction quality, download failures, latency, and battery use. A model can pass offline tests but fail on a particular device because of an unsupported operator or unexpected input format.
Use a compatibility rule that considers both the model and the runtime. A newer model may require an app update, a different delegate, or more memory. If validation fails, keep the old model and report a diagnostic event. If production metrics degrade, stop the rollout and restore the previous version.
Exercise
Exercise
Why should an app download a new model to a temporary path and retain the previous model?
Show answer
The temporary path prevents incomplete files from becoming active, while the previous model provides a known-good rollback target if validation or production monitoring detects a problem.