Cannot upload custom model from Firebase for android app

Viewed 68

According to spec for working with ML on android devices I have uploaded my custom model on https://console.firebase.google.com/project and have written teh following android app code:

public class ImportUnFuncModel {
    private Interpreter interpreter = null;
    private static final String TAG = "ImportUnFuncModel";

    public ImportUnFuncModel() {
        CustomModelDownloadConditions conditions = new CustomModelDownloadConditions.Builder()
            .requireWifi()
            .build();

        FirebaseModelDownloader.getInstance()
            .getModel("FindFunc",DownloadType.LOCAL_MODEL, conditions)
                .addOnFailureListener(new OnFailureListener() {
                      @Override
                      public void onFailure(@NonNull Exception e) {
                          Log.i(TAG, "onFailure exeption : " + e.toString());
                      }
                })
                .addOnSuccessListener(new OnSuccessListener<CustomModel>() {
                    @Override
                    public void onSuccess(CustomModel model) {
                        Log.i(TAG, "onSuccess model : " + model.toString());
                        File modelFile = model.getFile();
                        if (modelFile != null) {
                            interpreter = new Interpreter(modelFile);
                            Log.i(TAG, "onSuccess interpreter has been created successful : " + modelFile.toString());
                        }
                    }
                });
    }

    public Interpreter getInterpreter() {
        return interpreter;
    }
}

Unfortunatelly my model loading is failed with error: FirebaseMlException: Model download in bad state - please retry Please explain what I'm doing wrong...

1 Answers

Make sure you added all dependencies :

dependencies {
    // Import the BoM for the Firebase platform
    implementation platform('com.google.firebase:firebase-bom:30.3.1')

    // Declare the dependency for the Firebase ML model downloader library
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation 'com.google.firebase:firebase-ml-modeldownloader'

    // Also declare the dependency for the TensorFlow Lite library and specify its version
    implementation 'org.tensorflow:tensorflow-lite:2.3.0'
}

And permission:

<uses-permission android:name="android.permission.INTERNET" />

And, in my case I wasn't connected to Wifi, so removing requireWifi() method in conditions helped...

CustomModelDownloadConditions conditions = new CustomModelDownloadConditions.Builder()
.build();
Related