我正在嘗試將 google collab 用于其 tensorflow 環(huán)境,但路徑系統(tǒng)看起來有點復(fù)雜。我正在嘗試的是動態(tài)訪問我的火車和驗證文件夾的路徑,每個文件夾中都有貓和狗,以進(jìn)行分類。我正在使用 Keras/Tensorflow,因此我試圖從我的谷歌驅(qū)動器訪問這些文件夾。我的 cd 路徑目前是這樣的:cd "/content/drive/My Drive/data"我的文件夾數(shù)據(jù)包含訓(xùn)練和驗證文件夾的位置我正在做的是嘗試簡單地使用一些數(shù)據(jù)增強來進(jìn)行訓(xùn)練和驗證:from google.colab import filesfrom keras.preprocessing.image import ImageDataGeneratorfrom keras.models import Sequentialfrom keras.layers import Conv2D, MaxPooling2Dfrom keras.layers import Activation, Dropout, Flatten, Densefrom keras import backend as Kimport numpy as npfrom keras.preprocessing import imageimg_width, img_height = 150, 150train_data_dir = 'data/train'validation_data_dir = 'data/validation'nb_train_samples = 1000nb_validation_Samples = 100epochs = 50batch_size = 20if K.image_data_format() == 'channels_first': input_shape = (3, img_width, img_height)else: input_shape = (img_width, img_height, 3)train_datagen = ImageDataGenerator( rescale= 1. / 255, shear_range = 0.2, zoom_range=0.2, horizontal_flip=True)test_datagen = ImageDataGenerator(rescale=1. / 255)train_generator = train_datagen.flow_from_directory( train_data_dir, target_size=(img_width, img_height), batch_size=batch_size, class_mode='binary')validation_generator = test_datagen.flow_from_directory( validation_data_dir, target_size=(img_width, img_height), batch_size=batch_size, class_mode="binary")我收到以下錯誤:FileNotFoundError: [Errno 2] No such file or directory: 'data/train'我已經(jīng)安裝了我的驅(qū)動器,但我不知道如何訪問我的 google 驅(qū)動器文件夾,因為我會經(jīng)常使用 jupyter notebook,例如當(dāng)文件夾與筆記本位于同一路徑時。
1 回答

小怪獸愛吃肉
TA貢獻(xiàn)1852條經(jīng)驗 獲得超1個贊
首先掛載驅(qū)動器:
from google.colab import drive drive.mount('/content/drive')
然后使用:train_data_dir = '/content/drive/My Drive/data/train' validation_data_dir = '/content/drive/My Drive/data/validation'
添加回答
舉報
0/150
提交
取消