FileNotFoundError: [Errno 2] No such file or directory: 'PetImages\\Dog\\9519.jpg'

hi, im having this error in jupyter notebook, but works well in google colab, anybody know why?

FileNotFoundError Traceback (most recent call last)
Cell In[22], line 9
7 for index, file in enumerate(files):
8 plt.subplot(5,5, index+1)
----> 9 img = load_img(file)
10 img = np.array(img)
11 plt.imshow(img)

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\keras\src\utils\image_utils.py:235, in load_img(path, color_mode, target_size, interpolation, keep_aspect_ratio)
233 if isinstance(path, pathlib.Path):
234 path = str(path.resolve())
ā†’ 235 with open(path, ā€œrbā€) as f:
236 img = pil_image.open(io.BytesIO(f.read()))
237 else:

FileNotFoundError: [Errno 2] No such file or directory: ā€˜PetImages\Dog\9519.jpgā€™

Have you stored a file in Google colab, hardcoded its path, but canā€™t access it there from a local process?

Does the path have correct back slashes if on Windows, i.e. in a raw string or escaped?

Before I can explain why the file isnā€™t found, I need to understand why you expect it to be found.

What steps did you take to create the file(s) and put it (them) in place?

How was the files value created, and why does it have this path in it?

Does the path, PetImages\Dog\9519.jpg, look like what you expect? (In particular: do you understand what a relative path is, and what an absolute path is? Which kind of path do you think this one is? Is that what you expected to happen?)

1 Like