Created
May 6, 2019 04:45
-
-
Save shubham0204/19bb4823c8986a391c5d018518a50533 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 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