I'm trying the TFLite implementation for Image Classification using Mobile Net Transfer Learning example from TensorFlow for Poets 2
I'm able to succesfully complete the transfer learning using the four flower samples in the code lab and got the below screen
This is a continuous stream of images that's being classified.
I need to classify the image after taking the picture instead of stream and then take some action based on the result. Below is my approach for this.
- Create a basic camera app
- Take a picture and save it to storage
- The uri of the image is saved and then a drawable is created from the URI.
- This drawable is then converted to a bitmap.
- The bitmap size transformed to 224 x 224 to match the input of the Mobile Net model
- I'm receiving the accuracy in the ranges of 0.05 and 0.06 against the continuous stream sample from the Code Labs which gives accuracy in the range of 0.80 - 0.90 in the trained flower classes
Below is the code where I transform the bitmap to 224 x 224 size
private static Bitmap getResizedBitmap(Bitmap bm, int newWidth, int newHeight, boolean isNecessaryToKeepOrig) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// CREATE A MATRIX FOR THE MANIPULATION
Matrix matrix = new Matrix();
// RESIZE THE BIT MAP
matrix.postScale(scaleWidth, scaleHeight);
// "RECREATE" THE NEW BITMAP
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height, matrix, false);
if(!isNecessaryToKeepOrig){
bm.recycle();
}
return resizedBitmap;
}
The results turn out to be same even when I pass down the original bitmap to classifier which itself is converting the image to 224 x 224. Should I be doing some more additional processing on the images or do I need to change any configuration in the model ?
I think the problem is applyFilter() which smooth the probability. Just remove it then the probability should be showed as normal.
String classifyFrame(Bitmap bitmap) {
...
// smooth the results
//applyFilter(); <--remove it
...
}
I have the same problem and I want to sort a picture .I've found multiple calls to call the classification function. The results will tend to be correct. It's just a bad solution. enter image description here
来源:https://stackoverflow.com/questions/49954439/low-accuracy-with-static-image-on-tflite-demo-model