arm*_*ana 1 deep-learning conv-neural-network keras google-colaboratory
即使我将我的 Google Drive(及其中的数据集)定义为 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)
Run Code Online (Sandbox Code Playgroud)
我认为你/在你的/content/drive...。
通常通过以下方式挂载您的云端硬盘文件
from google.colab import drive
drive.mount('/content/drive')
Run Code Online (Sandbox Code Playgroud)
https://colab.research.google.com/notebooks/io.ipynb#scrollTo=u22w3BFiOveA
小智 5
挂载后,进入数据集文件夹。
cd content/drive/My Drive/Convolutional_Neural_Networks/dataset/
Run Code Online (Sandbox Code Playgroud)
不要使用!。然后将您的目录设置为./training_set
| 归档时间: |
|
| 查看次数: |
41960 次 |
| 最近记录: |