Created
October 29, 2018 17:13
-
-
Save munhra/e07af00a2c5d25b73da3105131d788f5 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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