I'm trying to access a dataset directly from my computer in Google Colab from a Youtube tutorial and I keep getting errors saying the file or directory doesn't exist. I've tried writing the path name differently, using '\' instead of '/', using r"...",copying the exact code from the tutorial and directly copying the path from properties and nothing works. I've found similar questions on SO but nothing that helps. Here is my code:
import numpy as np
import matplotlib.pyplot as plt
import os
import cv2
DATADIR = "C:/Datasets/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
These are my errors:
FileNotFoundError Traceback (most recent call last)
<ipython-input-15-f8d293e3d38a> 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: '/Datasets/PetImages/Dog'
You have to upload your files first.
from google.colab import files
uploaded = files.upload()
There are various ways to load the external data. Please check this link
I was getting the same error.
I got the solution by mounting the google drive in colab and then running the
import pandas as pd
data = pd.read_csv(path, header=0)
data
And it worked well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With