Skip to content

Instantly share code, notes, and snippets.

@shubham0204
Created May 6, 2019 04:45
Show Gist options
  • Save shubham0204/19bb4823c8986a391c5d018518a50533 to your computer and use it in GitHub Desktop.
Save shubham0204/19bb4823c8986a391c5d018518a50533 to your computer and use it in GitHub Desktop.
public float getSimilarity ( Bitmap image1 , Bitmap image2 ) {
try {
Interpreter interpreter = new Interpreter( loadModelFile() ) ;
int INPUT_DIM = 32;
float[][] x1 = new float[][]{mapBitmapToFloatArray( resizeBitmap( image1 , INPUT_DIM) , INPUT_DIM) };
float[][] x2 = new float[][]{mapBitmapToFloatArray( resizeBitmap( image2 , INPUT_DIM) , INPUT_DIM) };
Object[] inputs = { x1 , x2 } ;
Map<Integer, Object> outputs = new HashMap<>();
outputs.put(0, new float[1][1] );
interpreter.runForMultipleInputsOutputs( inputs , outputs ) ;
float[][] similarity = ( float[][] )outputs.get( 0 ) ;
return similarity[0][0] ;
}
catch (IOException e) {
e.printStackTrace();
return RECOGNIZER_ERROR_CODE;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment