【发布时间】:2019-11-03 19:52:34
【问题描述】:
我正在尝试从 Google Colab 访问我放入 Google Drive 中的数据集(通过安装我的驱动器并使用 DATADIR 变量指定文件夹的路径);但是,当尝试对 DATADIR 变量执行操作时,它说目录不存在。
我尝试了其他将数据集导入 Colab 的方法,但这些方法在我使用的代码中存在自己的问题。我宁愿只安装我的 Google Drive。
这是我安装驱动器的方式:
from google.colab import drive
drive.mount('/content/drive')
这是我得到错误的地方:
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)
这是错误信息(图片):
FileNotFoundError: [Errno 2] No such file or directory: 'content/drive/My Drive/Colab Notebooks/Datasets/Cats and Dogs/Dog'
出现在这一行:for img in os.listdir(path):
文件夹存在的证明:当我在 Colab 中单击“文件”时,我可以轻松导航到该文件夹。
【问题讨论】:
-
可能在
DataDir中缺少最初的/ -
谢谢!如果您将此作为答案发布,我可以接受。
标签: python dataset google-colaboratory