Image data cannot be converted to float


#1

Trying to do Lesson 8, Part 2 (pascal.ipynb notebook) and am unable to display an image. Receive the error:
Image data cannot be converted to float

Occurs specifically on the “ax = show_img(im)” section.

I am able to open the image via the following:
im = open_image(IMG_PATH/im0_d[FILE_NAME]);im

but not with:
plt.imshow(IMG_PATH/im0_d[FILE_NAME])

Something that matplotlib doesn’t like. Any thoughts?


#2

After more troubleshooting (although no solution), the issue seems to be related to the data types.

the open_image() function returns a fastai.vision.image.Image object, but the plt.imgshow() needs an array or nparray.
I tried to simply take the Image object and use np.asarray(Image_object) and then call plt.imgsho(), but same error.

Can anyone run the pascal.ipynb notebook and get the images to display?


(Puneet Girdhar) #3

That was a teaser and certainly compelled us to look more into the code.

You can use below code to plot the image

plt.imshow(image2np(im.data))

or

show_img(image2np(im.data))


#4

Thanks so much! That worked! I was stuck for a week, so thank you for helping me move forward. Have a great weekend.