Loading an image error on gradio classification

Hi,
I am a newbie, sorry if this has been asked, tried searching for similar problem, couldn’t find it.
I am trying to run a simple cat/dog classification problem. however when I click submit, an error occurs.see below:(it seems as a newbie I can only attach one file for now, sorry for copy and paste)

File “/usr/local/lib/python3.7/dist-packages/keras_preprocessing/image/utils.py”, line 113, in load_img
with open(path, ‘rb’) as f:
TypeError: expected str, bytes or os.PathLike object, not numpy.ndarray

here’s my code for that particular error:

I am not understanding why it would require an explicit url link on my function.
kindly assist,
thanks.

Hello! :wave:

Gradio’s gr.inputs.Image already gives you a NumPy array representing the image, so load_img and img_to_array are not needed. If you need a specific size, this can be set using the shape parameter to gr.inputs.Image.

Check out this Colab notebook.

Hope this helps :slightly_smiling_face:

hi Beneyal,
thank you for the response. I also tried that and it did solved that error. However, it created a new one:
return {class_name[i]: float(results[i]) for i in range(2)}
IndexError: list index out of range.
this is the function in question.

the label class has 2 names, cat and dog. the predictions are 2 as well. so this stuns me out.

Hmm… class_names is obviously of size 2, so the main suspect is results. Could you please inspect the shape of the prediction before the call to .tolist()?

so I included reshape()…see below.

it removed that error. now a new one pops up…crying:

File “/usr/local/lib/python3.7/dist-packages/numpy/core/fromnumeric.py”, line 44, in _wrapit
result = getattr(asarray(obj), method)(*args, **kwds)
TypeError: order must be str, not int

am pulling my hair(from my bald head)

Well, that’s unfortunate. :thinking:

What kind of model are you using? I can try setting up a minimal working example to send you and we can go from there.

I trained a densenet121 model as s feature extractor. I can send you the serialized model.
I also used data augmentation(ImageDataGenerator) to preprocessed it, kindly forward me your email address and I’ll send you the model and the whole notebook.
thanks.