Migrate TensorFlow Lite models from Firebase ML to Cloud Storage

If you use Firebase Machine Learning to host custom models , you must migrate to another solution before the Firebase ML hosting service is shut down on June 15, 2027.

One alternative you might use is to host your models using Cloud Storage for Firebase instead. Follow this guide to migrate your models from Firebase ML to Cloud Storage.

Download your TensorFlow Lite models

If you don't already have your models stored locally, download them from your Firebase project. You have two options for doing so:

Download them one at a time from the Firebase console

  1. Open the Machine Learning page section in the Firebase console.
  2. For each model you want to migrate, click its three-dot overflow menu, then click Download model.

Download all of your hosted models in bulk

  1. Open the Machine Learning page in the Firebase console.
  2. Click the Get command for bulk downloadbutton to get a curl command that downloads all of the models in the project. These URLs will expire in 7 days.
  3. Run the command in your local terminal or in Cloud Shell . If using Cloud Shell, note its 5GB disk storage limit . The command will download your models to a local folder named hosted_models .

Host your models using Cloud Storage

Once you have your models locally, you need to upload them to a Cloud Storage bucket.

Choose the upload method that matches your needs:

Upload your models one at a time

  1. Create a Storage bucket: in the Firebase console, navigate to Databases & Storage > Storage and follow the onboarding steps to create a bucket if you haven't already. Note that this requires a billing account; see Firebase pricing for details.
  2. Still in the Storagesection, upload your .tflite model files to the desired path.

Upload your models in bulk

  1. Create a Storage bucket: in the Firebase console, navigate to Databases & Storage > Storage and follow the onboarding steps to create a bucket if you haven't already. Note that this requires a billing account; see Firebase pricing for details.
  2. Use the following gcloud command to upload all models from your local hosted_models folder:

     gcloud  
    storage  
    rsync  
    --recursive  
    ./hosted_models  
    gs://<your-storage-bucket>/models/ 
    

Configure security and app integration

  1. Ensure your Storage security rules allow your app to read the model files. For example, you can restrict access to authenticated users.

  2. Add Storage to your app: follow the setup guides for Android , Apple , or Flutter .

  3. Update your application code to download the .tflite files from your new Storage bucket.

    Android

      modelRef 
      
     = 
      
     storage 
     . 
     getReferenceFromUrl 
     ( 
     "gs://YOUR_BUCKET/path/to/model.tflite" 
     ) 
     val 
      
     localFile 
      
     = 
      
     File 
     . 
     createTempFile 
     ( 
     "models" 
     , 
      
     "tflite" 
     ) 
     modelRef 
     . 
     getFile 
     ( 
     localFile 
     ). 
     addOnSuccessListener 
      
     { 
      
     // Local temp file has been created 
     }. 
     addOnFailureListener 
      
     { 
      
     // Handle any errors 
     } 
     
    

    Apple

      let 
      
     gsReference 
      
     = 
      
     storage 
     . 
     reference 
     ( 
     forURL 
     : 
      
     "gs://YOUR_BUCKET/path/to/model.tflite" 
     ) 
     // Create local filesystem URL 
     let 
      
     localURL 
      
     = 
      
     URL 
     ( 
     string 
     : 
      
     "path/to/model.tflite" 
     ) 
     ! 
     // Download to the local filesystem 
     let 
      
     downloadTask 
      
     = 
      
     gsReference 
     . 
     write 
     ( 
     toFile 
     : 
      
     localURL 
     ) 
      
     { 
      
     url 
     , 
      
     error 
      
     in 
      
     if 
      
     let 
      
     error 
      
     = 
      
     error 
      
     { 
      
     // Uh-oh, an error occurred! 
      
     } 
      
     else 
      
     { 
      
     // Local file URL for "model.tflite" is returned 
      
     } 
     } 
     
    

    Flutter

      final 
      
     modelRef 
      
     = 
      
     FirebaseStorage 
     . 
     instance 
     . 
     refFromURL 
     ( 
     "gs://YOUR_BUCKET/path/to/model.tflite" 
     ); 
     final 
      
     appDocDir 
      
     = 
      
     await 
      
     getApplicationDocumentsDirectory 
     (); 
     final 
      
     filePath 
      
     = 
      
     " 
     ${ 
     appDocDir 
     . 
     absolute 
     } 
     /models/model.tflite" 
     ; 
     final 
      
     file 
      
     = 
      
     File 
     ( 
     filePath 
     ); 
     final 
      
     downloadTask 
      
     = 
      
     modelRef 
     . 
     writeToFile 
     ( 
     file 
     ); 
     downloadTask 
     . 
     snapshotEvents 
     . 
     listen 
     (( 
     taskSnapshot 
     ) 
      
     { 
      
     switch 
      
     ( 
     taskSnapshot 
     . 
     state 
     ) 
      
     { 
      
     case 
      
     TaskState 
     . 
     running: 
      
     // TODO: Handle this case. 
      
     break 
     ; 
      
     case 
      
     TaskState 
     . 
     paused: 
      
     // TODO: Handle this case. 
      
     break 
     ; 
      
     case 
      
     TaskState 
     . 
     success: 
      
     // TODO: Handle this case. 
      
     break 
     ; 
      
     case 
      
     TaskState 
     . 
     canceled: 
      
     // TODO: Handle this case. 
      
     break 
     ; 
      
     case 
      
     TaskState 
     . 
     error: 
      
     // TODO: Handle this case. 
      
     break 
     ; 
      
     } 
     }); 
     
    

    Once the model is downloaded, you can use your existing Tensorflow Lite library to load the model and use it.

  4. (Optional) Consider using Firebase Remote Config to dynamically update model paths in your app without requiring a new release.

Optional: Migrate to the LiteRT CompiledModel API

If your app still uses the legacy TensorFlow Lite Interpreter API, consider migrating to the LiteRT CompiledModel API , which offers improved hardware acceleration support and other improvements over the legacy API.

Create a Mobile Website
View Site in Mobile | Classic
Share by: