gpt4 book ai didi

keras - Google Colab 无法访问驱动器内容

转载 作者:行者123 更新时间:2023-12-05 08:20:16 26 4
gpt4 key购买 nike

即使我将我的 Google 云端硬盘(以及其中的数据集)定义为 google colab,但是当我运行我的代码时,我给出了这个错误:FileNotFoundError: [Errno 2] No such file or directory: 'content/drive/My Drive/....

我已经在 google colab 中定义了 google drive 并且我可以通过 google colab 访问它但是当我运行我的代码时我给出了这个错误

from keras.models import Sequential
from keras.layers import Convolution2D
from keras.layers import MaxPooling2D
from keras.layers import Flatten
from keras.layers import Dense
model=Sequential()
model.add(Convolution2D(32,3,3,input_shape=(64,64,3),activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Convolution2D(32,3,3,activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Flatten())
model.add(Dense(output_dim=128,activation='relu'))
model.add(Dense(output_dim=1,activation='sigmoid'))
model.compile(optimizer='adam',loss='binary_crossentropy',metrics=['accuracy'])

from keras.preprocessing.image import ImageDataGenerator
train_datagen=ImageDataGenerator(
rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True)
test_datagen=ImageDataGenerator(rescale=1./255)

training_set=train_datagen.flow_from_directory(
directory='content/drive/My Drive/Convolutional_Neural_Networks/dataset/training_set',
target_size=(64,64),
batch_size=32,
class_mode='binary')
test_set=test_datagen.flow_from_directory(
directory='content/drive/My Drive/Convolutional_Neural_Networks/dataset/test_set',
target_size=(64,64),
batch_size=32,
class_mode='binary')

#train
model.fit_generator(
training_set,
samples_per_epoch=8000,
nb_epoch=2,
validation_data=test_set,
nb_val_samples=1000)

import numpy as np
from keras.preprocessing import image
test_image=image.load_img('sunn.jpg',target_size=(64,64))
test_image=image.img_to_array(test_image)
test_image=np.expand_dims(test_image,axis=0)
result=model.predict(test_image)
training_set.class_indices
if result[0][0] >= 0.5:
prediction='dog'
else:
prediction='cat'
print(prediction)

最佳答案

挂载后,进入数据集文件夹。

cd content/drive/My Drive/Convolutional_Neural_Networks/dataset/

不要使用!。然后将您的目录设置为 ./training_set

关于keras - Google Colab 无法访问驱动器内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54269091/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com