Search code examples
javaandroidfirebasefirebase-mlkit

Android FirebaseML - Local model is not registered:


Hi I'm building an app for a personal project, What I want to do is to use a model (.tflite) hosted in Firebase MLKit on my android app.

Whenever I want to consult my model I call a function that contains the following code:

FirebaseModelDownloadConditions.Builder conditionsBuilder = new FirebaseModelDownloadConditions.Builder().requireWifi();

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
      conditionsBuilder = conditionsBuilder
             .requireCharging()
             .requireDeviceIdle();
}

FirebaseModelDownloadConditions conditions = conditionsBuilder.build();

FirebaseRemoteModel cloudSource = new FirebaseRemoteModel.Builder("places-recommend")
        .enableModelUpdates(true)
        .setInitialDownloadConditions(conditions)
        .setUpdatesDownloadConditions(conditions)
        .build();

FirebaseModelManager.getInstance().registerRemoteModel(cloudSource);

FirebaseModelOptions options = new FirebaseModelOptions.Builder()
        .setRemoteModelName("places-recommend")
        .setLocalModelName("places-recommend")
        .build();

FirebaseModelInterpreter firebaseInterpreter = FirebaseModelInterpreter.getInstance(options);

FirebaseModelInputOutputOptions inputOutputOptions =
        new FirebaseModelInputOutputOptions.Builder()
                .setInputFormat(0, FirebaseModelDataType.FLOAT32, new int[]{1, 3})
                .setOutputFormat(0, FirebaseModelDataType.FLOAT32, new int[]{1, 34})
                .build();

However the interpreter line:

FirebaseModelInterpreter firebaseInterpreter = FirebaseModelInterpreter.getInstance(options);

throws a FirebaseMLException:

Local model is not registered: places-recommend

Im following the Firebase guide, but i havent found a solution yet, any help would be appreciated.


Solution

  • You seemed to have registered the remote model but not the local one. When you declare your model options you are trying to setLocalModelName but the model hasn't been registered. Add the following line right before you set the options variable:

    FirebaseModelManager.getInstance().registerLocalModel(localSource);

    Alternatively, if you don't need to use a local model and only want to use the one you have published via the Firebase console, you can remove the following line: .setLocalModelName("places-recommend")