Bowis
Bowis

Reputation: 632

FileNotFoundError: [Errno 2] No such file or directory | Mac + Google Colab

I am working in a file on Google Colab and using the follow code:

import numpy as np
import matplotlib.pyplot as plt
import os
import cv2

DATADIR="/Users/boris/PetImages"
CATEGORIES= ["Dog","Cat"]

for category in CATEGORIES:
  path = os.path.join(DATADIR, category) 
  for img in os.listdir(path):
    img_array = cv2.imread(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
    plt.imshow(img_array, cmap="gray")
    plt.show()
    break
break

I am trying to import two folders on my mac. However I keep on getting the following error:

---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-36-4ea265030377> in <module>()
      9 for category in CATEGORIES:
     10   path = os.path.join(DATADIR, category)
---> 11   for img in os.listdir(path):
     12     img_array = cv2.imread(os.path.join(path,img), cv2.IMREAD_GRAYSCALE)
     13     plt.imshow(img_array, cmap="gray")

FileNotFoundError: [Errno 2] No such file or directory: "/Users/boris/PetImages/Dog"

Upvotes: 0

Views: 7638

Answers (1)

jakevdp
jakevdp

Reputation: 86463

Google colab runs on a remote virtual machine that has no access to your local file system. To use such files, you will first have to upload them to the Colab machine.

See https://colab.research.google.com/notebooks/io.ipynb for information on various approaches to accessing data in Colab.

Upvotes: 3

Related Questions