google-coral/pycoral

tflite: grayscale shape using pycoral with PIL

peepo opened this issue · 2 comments

peepo commented

for:
image = Image.open(image_file).convert('RGB').resize(size, Image.ANTIALIAS)
ValueError: could not broadcast input array from shape (64,64) into shape (64,64,1)
else
image = Image.open(image_file).resize(size, Image.ANTIALIAS)
ValueError: could not broadcast input array from shape (64,64,3) into shape (64,64,1)

I'd like 64,64,1

using only:
from pycoral.utils.edgetpu import make_interpreter
from pycoral.adapters import common
import PIL
from PIL import Image

Full error:

Traceback (most recent call last):
File "edge.py", line 16, in
common.set_input(interpreter, image)
File "/usr/lib/python3/dist-packages/pycoral/adapters/common.py", line 75, in set_input
input_tensor(interpreter)[:, :] = data
ValueError: could not broadcast input array from shape (64,64) into shape (64,64,1)

Apologies if this is working as intended,
I did not find a way when creating .tflite with numpy to create 3D array such as 1,64,64
as that also produces an error conv2d requires 4D minimum.

thanks!

I am planning to use monochrome sensor, and would prefer not to convert to RGB.

peepo commented

I tried tf.io.decode_image & tf.io.decode_bmp, ie :
img = tf.io.read_file('apple64.png')
img = tf.io.decode_image(img, channels=0)
tf.expand_dims(img, -1).shape.as_list()
model_1 = Sequential()

without success: ValueError: could not broadcast input array from shape (64,64) into shape (64,64,1)
https://discuss.tensorflow.org/t/loading-16-grayscale-png-in-tf-lite/5461

peepo commented

Clarification:
img = img[:, :, np.newaxis] or img = np.expand_dims(img, axis=(0, -1)) are also similar,
the tensorflow works fine, it's when one tries to use the .tflite file created that this error arises.
I did not find a reduced testcase or other example.