Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tflite: grayscale shape using pycoral with PIL #135

Open
peepo opened this issue Nov 13, 2023 · 2 comments
Open

tflite: grayscale shape using pycoral with PIL #135

peepo opened this issue Nov 13, 2023 · 2 comments

Comments

@peepo
Copy link

peepo commented Nov 13, 2023

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
Copy link
Author

peepo commented Nov 14, 2023

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 peepo changed the title grayscale shape using pycoral with PIL tflite: grayscale shape using pycoral with PIL Nov 14, 2023
@peepo
Copy link
Author

peepo commented Nov 14, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant