Skip to content

Instantly share code, notes, and snippets.

@munhra
Created October 29, 2018 17:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save munhra/e07af00a2c5d25b73da3105131d788f5 to your computer and use it in GitHub Desktop.
Save munhra/e07af00a2c5d25b73da3105131d788f5 to your computer and use it in GitHub Desktop.
public void runModel(String absolutePath) {
if (mInterpreter == null) {
Log.e(TAG, "Image classifier has not been initialized; Skipped.");
return;
}
float[][][][] imgData = cropImage(absolutePath);
try {
FirebaseModelInputs inputs = new FirebaseModelInputs.Builder().add(imgData).build();
// Here's where the magic happens!!
Log.d(TAG,"Here's where the magic happens!!");
mInterpreter
.run(inputs, mDataOptions)
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
e.printStackTrace();
showToast("Error running model inference "+e.toString());
mlKitListener.machineLearningError(e);
}
})
.continueWith(
new Continuation<FirebaseModelOutputs, Boolean>() {
@Override
public Boolean then(Task<FirebaseModelOutputs> task) {
float[][] result = task.getResult().<float[][]>getOutput(0);
mlKitListener.machineLearningResult(result);
showToast("- Class 1 - "+result[0][0]+" - Class 2 - "+result[0][1]);
calculateMLSimpleResult(result);
return true;
}
});
} catch (FirebaseMLException e) {
e.printStackTrace();
showToast("Error running model inference");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment