Reputation: 232
I'm trying to access a dataset I put in my Google Drive from Google Colab (by mounting my drive and using the DATADIR variable to specify the path of the folder); however, when trying to perform operations on the DATADIR variable, it says the directory doesn't exist.
I've tried other methods of getting the dataset into Colab, but those come with their own problems in the code I'm using. I'd prefer to just stick to mounting my Google Drive.
Here's how I mounted my drive:
from google.colab import drive
drive.mount('/content/drive')
And here's where I'm getting the error:
DATADIR = "content/drive/My Drive/Colab Notebooks/Datasets/Cats and Dogs"
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)
Here's the error message (picture):
FileNotFoundError: [Errno 2] No such file or directory: 'content/drive/My Drive/Colab Notebooks/Datasets/Cats and Dogs/Dog'
It occurs on this line: for img in os.listdir(path):
Proof that the folder exists: when I click on 'Files' in Colab, I can navigate to the folder easily.
Upvotes: 0
Views: 9446
Reputation: 56
"Maybe missing the initial / in DataDir" from Mark, June,21 2019 That solution works for me
Upvotes: 0
Reputation: 36
restart the notebook then inside the cell, where you use the script, write: !ls It will show the corrent path. I noticed that even if you move the script the directory remain the same
Upvotes: 1