Open prince-kumar-15 opened 6 years ago
I changed some byte data type to float type. and it worked well!
Which ones exactly? @ZZANZU
@aashutoshrathi
I think this is not real solution, but it worked well(maybe...?)
@Override
public List<Recognition> recognizeImage(Bitmap bitmap) {
ByteBuffer byteBuffer = convertBitmapToByteBuffer(bitmap);
float[][] result = new float[1][labelList.size()];
long startTime = SystemClock.uptimeMillis();
interpreter.run(byteBuffer, result);
return getSortedResult(result);
}
I changed the 'result''s type to float, and
@SuppressLint("DefaultLocale")
private List<Recognition> getSortedResult(float[][] labelProbArray) {
PriorityQueue<Recognition> pq =
new PriorityQueue<>(
MAX_RESULTS,
new Comparator<Recognition>() {
@Override
public int compare(Recognition lhs, Recognition rhs) {
return Float.compare(rhs.getConfidence(), lhs.getConfidence());
}
});
for (int i = 0; i < labelList.size(); ++i) {
float confidence = (labelProbArray[0][i] * 100) / 127.0f; // deleted '& 0xff' and multiplied by 100(but I'm not sure, but it showed me some cool accuracy value...
if (confidence > THRESHOLD) {
pq.add(new Recognition("" + i,
labelList.size() > i ? labelList.get(i) : "unknown",
confidence));
}
}
'getSortedResult' function gets float value, and it calculates the 'confidenc'e value.
This is what I did temporarily just for deleting the errors. If you have any solution, please let me know.
hy i did this but confidence value not increase from 0
I have changed the required things for inceptionV3 as mentioned below but still its not working. its giving me an error : cannot convert an tensorflowlite tensor with type float32 to a java object of type [[b (which is compatible with the tensorflowlite type uint8)
Changes that I did :
private static final int INPUT_SIZE = 299; /**
The inception net requires additional normalization of the used input. / private static final int IMAGE_MEAN = 128; private static final float IMAGE_STD = 128.0f; private ByteBuffer convertBitmapToByteBufferForInceptionV3(Bitmap bitmap) { ByteBuffer byteBuffer = ByteBuffer.allocateDirect(BATCH_SIZE inputSize inputSize PIXEL_SIZE 4); byteBuffer.order(ByteOrder.nativeOrder()); int[] intValues = new int[inputSize inputSize]; bitmap.getPixels(intValues, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight()); int pixel = 0; for (int i = 0; i < inputSize; ++i) { for (int j = 0; j < inputSize; ++j) { final int val = intValues[pixel++];
}