I have followed the implementation of this medium post to deploy my Keras model to Android. I have used Dense layers having 9 nodes along with softmax activation in the output layer, as opposed to the Global Average Pooling used in the post. My h5 file of the model predicts accurately in python, but when I use pb file in Android, its prediction is wrong. Moreover, the floating point values after prediction are found a little bit different in different Android devices. Is there any problem with the implementation? Most probably there is a little mistake in line 16 of the file ConvertToTensorflow.py
(it should be keras_model.outputs
instead of keras_model.output
). I have corrected it, but yet the problem persists.
Asked
Active
Viewed 147 times
0

Preetom Saha Arko
- 2,588
- 4
- 21
- 37
1 Answers
0
It turns out that normalizeBitmap
function of ImageUtils.java
was actually normalizing each pixel of the image while I simply divided each pixel value by 255 while training my model in python. So I changed 3 lines of the code:
output[i * 3] = (float)(((val >> 16) & 0xFF)/255.0);
output[i * 3 + 1] = (float)(((val >> 8) & 0xFF)/255.0);
output[i * 3 + 2] = (float)((val & 0xFF)/255.0);

Preetom Saha Arko
- 2,588
- 4
- 21
- 37