I am building a sign language recognition using an InceptionV3 model which i have converted into a tflite model. This is the default model from the tflite file:
Model4 model = Model4.newInstance(context);
// Creates inputs for reference.
TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 240, 135, 3}, DataType.FLOAT32);
inputFeature0.loadBuffer(byteBuffer);
// Runs model inference and gets result.
Model4.Outputs outputs = model.process(inputFeature0);
TensorBuffer outputFeature0 = outputs.getOutputFeature0AsTensorBuffer();
// Releases model resources if no longer used.
model.close();
} catch (IOException e) {
// TODO Handle the exception
}
In which I have tweaked my codes accordingly to get the prediction from a float of values.
Model4 model = Model4.newInstance(getApplicationContext());
// Creates inputs for reference.
TensorBuffer inputFeature0 = TensorBuffer.createFixedSize(new int[]{1, 240, 135, 3}, DataType.FLOAT32);
TensorImage tensorImage = new TensorImage(DataType.FLOAT32);
tensorImage.load(bitmap);
ByteBuffer byteBuffer = tensorImage.getBuffer();
byteBuffer.order(ByteOrder.nativeOrder());
inputFeature0.loadBuffer(byteBuffer);
// Runs model inference and gets result.
Model4.Outputs outputs = model.process(inputFeature0);
TensorBuffer outputFeature0 = outputs.getOutputFeature0AsTensorBuffer();
float[] confidences = outputFeature0.getFloatArray();
String[] classes = {"1a", "2i", "3u"};
int maxPos = 0;
float maxConfidence = 0;
for(int i=0; i<confidences.length; i++){
if(confidences[i] > maxConfidence){
maxConfidence = confidences[i];
maxPos = i;
};
}
result.setText(classes[maxPos]);
// Releases model resources if no longer used.
model.close();
} catch (IOException e) {
// TODO Handle the exception
}
Unfortunately for every different image input, I get back the same output which is 3a.
This is very weird as during my python machine learning evaluation, the accuracy of prediction were always accurate.
Would like some enlightenment on how to workaround this error as I've been solving for days and sourced the entire internet to no avail. Thank you!