Firebase ML Model Downloader
This page is archived and might not reflect the latest version of the FlutterFire plugins. You can find the latest information on firebase.google.com:
Once installed, you can access the
firebase_ml_model_downloader plugin by importing it in your Dart code:
Before using the package, you must first have ensured you have initialized FlutterFire.
To create a new downloader instance, call the
instance getter on
By default, this allows you to interact with the downloader using the default Firebase App used whilst installing FlutterFire on your
platform. If however you'd like to use a secondary Firebase App, use the
#List downloaded models
To access any locally downloaded models on the device, call the
listDownloadedModels method. The response contains a list of any locally
downloaded custom models:
A custom model contains information such as the name, size and unique hash of the model. It also contains access to the local
File on the device,
allowing you to provide it to an interpreter plugin.
Once a custom model has been downloaded, you can access it using the
If you're working with a 3rd party interpreter such as
use the returned file to access the model:
#Downloading a model
Once you have deployed a TensorFlow model, you can download them to your
device using the
getModel method, specifying the model name and download options.
The above code will download the latest available
myModel model to the device, since the
FirebaseModelDownloadType.latestModel has been specified.
The method accepts 3 download types for differing behavior:
|Returns the current model if present, otherwise triggers new download (or finds one in progress) and only completes when download is finished.|
|Returns the current model if present and triggers an update to fetch a new version in the background. If no local model is present triggers a new download (or finds one in progress) and only completes when download is finished.|
|Returns the latest model. Checks if latest model is different from local model. If the models are the same, returns the current model. Otherwise, triggers a new model download and returns when this download finishes.|
You can also provide specific conditions for the download, such as whether the model should be downloaded whilst the device has access to cellular data, or if the device is charging.
To provide conditions, provide a
FirebaseModelDownloadConditions instance to the
#Deleting a download model
To delete a model from the device, call the
Note; this does not delete the model from your Firebase project, only the local copy on the device. You can download it again at any time.