Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code is not working with inceptionV3 model [cannot convert an tensorflowlite tensor with type float32 to a java object of type [[b (which is compatible with the tensorflowlite type uint8)] #3

Open
prince-kumar-15 opened this issue Apr 24, 2018 · 4 comments

Comments

@prince-kumar-15
Copy link

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++];

                byteBuffer.putFloat((((val >> 16) & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
                byteBuffer.putFloat((((val >> 8) & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
                byteBuffer.putFloat(((val & 0xFF) - IMAGE_MEAN) / IMAGE_STD);
            
        }
    }
    return byteBuffer;
}
@ZZANZU
Copy link

ZZANZU commented May 15, 2018

I changed some byte data type to float type. and it worked well!

@aashutoshrathi
Copy link

Which ones exactly? @ZZANZU

@ZZANZU
Copy link

ZZANZU commented Jul 12, 2018

@aashutoshrathi

https://github.com/COSE471/COSE471_android/blob/master/app/src/main/java/com/example/android/alarmapp/tflite/TensorFlowImageClassifier.java

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.

@waleedkalyar
Copy link

hy i did this but confidence value not increase from 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants