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_imgwith open(path, ‘rb’) as f:TypeError: expected str, bytes or os.PathLike object, not numpy.ndarrayhere’s my code for that particular error:Screenshot 2022-02-12 at 09.33.001346×362 65.4 KBI am not understanding why it would require an explicit url link on my function.kindly assist,thanks.
2022-02-12T13:59:59Z
Hello!Gradio’sgr.inputs.Imagealready gives you a NumPy array representing the image, soload_imgandimg_to_arrayare not needed. If you need a specific size, this can be set using theshapeparameter togr.inputs.Image.Check out thisColab notebook.Hope this helps
2022-02-13T07:25:26Z
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.Screenshot 2022-02-13 at 09.23.501364×322 58 KBthe label class has 2 names, cat and dog. the predictions are 2 as well. so this stuns me out.
2022-02-13T08:17:39Z
Hmm…class_namesis obviously of size 2, so the main suspect isresults. Could you please inspect the shape of the prediction before the call to.tolist()?
2022-02-14T09:26:08Z
so I included reshape()…see below.Screenshot 2022-02-14 at 11.23.291356×388 151 KBit 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 _wrapitresult = getattr(asarray(obj), method)(*args, **kwds)TypeError: order must be str, not intam pulling my hair(from my bald head)
2022-02-14T09:35:41Z
Well, that’s unfortunate.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.
2022-02-14T09:40:47Z
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.