amitshekhariitbhu / Android-TensorFlow-Lite-Example

Android TensorFlow Lite Machine Learning Example
https://outcomeschool.com
Apache License 2.0
752 stars 228 forks source link

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 6 years ago

prince-kumar-15 commented 6 years ago

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; /**

ZZANZU commented 6 years ago

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

aashutoshrathi commented 6 years ago

Which ones exactly? @ZZANZU

ZZANZU commented 6 years ago

@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 commented 5 years ago

hy i did this but confidence value not increase from 0