我正在尝试使用Google Colab在CIFAR上训练CNN。出现以下错误:
OSError Traceback (most recent call last)
<ipython-input-5-d55609bb9b39> in <module>()
----> 1 images, labels = dataset_preprocessing('/content/gdrive/My Drive/Data/cifar/train', '/content/gdrive/My Drive/Data/cifar/labels.txt', (32,32),'/content/gdrive/My Driv\]\/training_image_pickle')
<ipython-input-4-79e4d13e78a2> in dataset_preprocessing(dataset_path, labels_file_path, image_size, image_paths_pickle)
14 image_paths = []
15
---> 16 for image_name in os.listdir(dataset_path):
17 try:
18 image_path = os.path.join(dataset_path, image_name)
OSError: [Errno 5] Input/output error: '/content/gdrive/Data/cifar/train'
下面是dataset_preprocessing
函数:
def dataset_preprocessing(dataset_path, labels_file_path, image_size, image_paths_pickle):
'''
Load Images and labels from dataset folder.
:param dataset_path:String, path to the train/test dataset folder
:param image_size: Tuple, single image size
:param image_path_pickle: String, name of a pickle file whre all imag paths will be saved
'''
with open(labels_file_path, 'r') as f:
classes = f.read().split('\n')[:-1]
images = []
labels = []
image_paths = []
for image_name in os.listdir(dataset_path):
try:
image_path = os.path.join(dataset_path, image_name)
images.append(image_loader(image_path, image_size))
image_paths.append(image_path)
for idx in range(len(classes)):
if classes[idx] in image_name: #Example: 0_frog.png
labels.append(idx)
except:
pass
with open(image_paths_pickle + '.pickle','wb') as f:
pickle.dump(image_paths, f)
assert len(images) == len(labels)
return np.array(images), np.array(labels)
最后,我使用了Colab文档中的以下代码来安装驱动器:
from google.colab import drive
drive.mount('/content/gdrive')