0
votes

I am very new to tensorflow lite app using kotlin.I have taken a sample kotlin code for image classification using mobilenet model and it is working fine and now i am trying it with my own custom image classifier model. I am using a VGG architecture with input shape of 32x32x3 and converted it to tflite and it is working correctly using tflite interpreter. But when i try this on the kotlin app i am facing the below error and i am finding it very hard to convert it to float due to val type in kotlin(auto type casting)

 fun recognizeImage(bitmap: Bitmap): List<Recognition> {
        val scaledBitmap = Bitmap.createScaledBitmap(bitmap, inputSize, inputSize, false)
        val byteBuffer = convertBitmapToByteBuffer(scaledBitmap)
        val result = Array(1) { ByteArray(labelList.size) }
        interpreter.run(byteBuffer, result)
        return getSortedResult(result)
    }

error log

E/Exception: java.lang.IllegalArgumentException: Cannot convert between a TensorFlowLite tensor with type FLOAT32 and a Java object of type [[B (which is compatible with the TensorFlowLite type UINT8).

how can i solve it

1

1 Answers

1
votes

Firstly you need to double check what type of input your model is expecting.

If it's quantized, the model is expecting UINT8 input in range [0, 255].

For original version VGG, I remember (not sure) that it expects float value in range [0, 1], which means you need to manually normalize your input data.