Hello,
I trained a Keras CNN model for a classification task using grayscale images (48x48x1). After training and saving the model, I now would like to use the model in an Android application, so I converted the trained model to a TFLite model.
After conversion, I did two things in order to confirm that the converted model works properly:


I tested running inferences on some grayscale test images using the TFLite model in Python, and got proper and expected results (using the same dimensions for the input as I used for training).


I inspected the TFLite model in Netron and confirmed that it expects an input of the following format: float32[1, 48, 48, 1].


The issue I am facing now is with loading input images to the TFLite model using Java in Android Studio. Since my model expects grayscale input images (1 channel), the total input bytes for one frame are supposed to be 48x48x1x4= 9216 bytes (the last 4 multiplied is because of the input being of FLOAT32 format). The problem is that the TensorImage input format, which is what the TFLite model supports, only supports RGB input images, which isn’t compatible with single-channel input images. In addition, Bitmap doesn’t even support storing grayscale images, so I wouldn’t know how to store any grayscale input images into a Bitmap and not have an extra number of bytes that would later cause issues.
I am not an expert in Android development and have slowly been learning and building things, so I understand there might be easy solutions that I’m overlooking. I would appreciate any help that comes my way!
Thanks,
Ahmad