Error in first CNN Challenge

I am trying to convert all images into arrays and append them to an aimag data list. But I am getting error in this that say-

UnidentifiedImageError Traceback (most recent call last)
in ()
2 for i in os.listdir§:
3 path = os.path.join(p,i)
----> 4 img = image.load_img(path)
5 print(image.img_to_array(img).shape)
6

2 frames
/usr/local/lib/python3.6/dist-packages/PIL/Image.py in open(fp, mode)
2860 warnings.warn(message)
2861 raise UnidentifiedImageError(
-> 2862 “cannot identify image file %r” % (filename if filename else fp)
2863 )
2864

UnidentifiedImageError: cannot identify image file <_io.BytesIO object at 0x7f04d191d678>

Here is my code-

https://colab.research.google.com/drive/1ZLQnf-O9P4KeGdSeILnc08mWtxT5NDBw?usp=sharing

Hey @sanchit123manchanda, just try printing the path like this :

for p in pokemons:
  for i in os.listdir(p):
    path = os.path.join(p,i)
    print(path)

You will see the problem itself and why is it coming.

I hope this clears your doubt !
Please mark the doubt as resolved in your doubts section ! :+1:
Happy Learning ! :slight_smile:

I checked it. All the paths looked fine. What can I do to rectify this error.

I got it. There are some files with unknown extensions such as .svg, .asp, etc. Should i ignore them or read them by a different method ?

See if you can find a common method to read all the files together or if u think the .svg or .asp files are not too many in number…u can simple ignore them.

I hope this clears your doubt ! :+1:
Happy Learning ! :slightly_smiling_face:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.