Hi!
I am a new with Python, and I have to produce a small Python script that load a 16bit PNG and run inference with TensorFlow Lite on a Coral board SDK, using an existing model with shape [224, 224, 1]. The input image is 224x224 16bit mono.
ValueError: could not broadcast input array from shape (224,224) into shape (224,224,1)
I assume I need to load the PNG file as a (224,224,1) array instead of a (224,224) array.
What is the proper way to load a grayscale PNG this way?
Can TFlite use 16bit mono PNG, or does it only support 24bit RGB?
TF has native functions to decode images loaded from files like decode_image() or decode_png()
Please, see this documentation page: tf.io.decode_image | TensorFlow v2.16.1
You can specify the number of channels that you need in a decoded tensor, which can be 1, 3, 4 or the same as in the original image.
Turns out that loading the PNG was not the issue. I am now testing with the Coral USB Accelerator, and I need to re-shape the array this way for it to fit my model file:
I can do this from the linux PC I’m working on. I do not remember if I had tried exactly that on the Coral Dev board.
I notice that processing these images require ~65ms, as opposed to the ~5ms requires to process the “bird” example images, despite the example parrot image being much larger. I guess if TFlite is optimized for 8bit input values (RGB) instead of 16 bit values.