0

We were doing a course project and faced this issue. The idea is simple, three categories: cats, dogs, and cars, the app should classify the photo in one of these. There are lots of tutorials how to implement an already taught net like ImageNet but we needed to do a custom one. I used Tensorflow Keras, saved model as h5 and then converted it to tflite with metadata, in which I specified resize and normalize options. Unfortunately, it didn't work at all.

Official Tensorflow documentation says that you need to preprocess the image like this

import org.tensorflow.lite.DataType;
import org.tensorflow.lite.support.image.ImageProcessor;
import org.tensorflow.lite.support.image.TensorImage;
import org.tensorflow.lite.support.image.ops.ResizeOp;

// Initialization code
// Create an ImageProcessor with all ops required. For more ops, please
// refer to the ImageProcessor Architecture section in this README.
ImageProcessor imageProcessor =
    new ImageProcessor.Builder()
        .add(new ResizeOp(224, 224, ResizeOp.ResizeMethod.BILINEAR))
        .build();

// Create a TensorImage object. This creates the tensor of the corresponding
// tensor type (uint8 in this case) that the TensorFlow Lite interpreter needs.
TensorImage tensorImage = new TensorImage(DataType.UINT8);

// Analysis code for every frame
// Preprocess the image
tensorImage.load(bitmap);
tensorImage = imageProcessor.process(tensorImage);

` We tried many times, and as I understand it's not needed if you specified metadata because without this it works a little bit better. I guess that the problem is that it does preprocessing automatically but I haven't find anywhere which interpolation method it uses or how can I override that interpolation method. In Keras I use ImageDataGenerator and flow_from_directory to load data and it uses nearest neighbour by default. I have no opportunity to train the model again so it would be better if you tell how can I override it in Android Studio. Thank you in advance

0 Answers0