ResNet50 目录问题
我正在运行 ResNet50 预训练模型来对青光眼和非青光眼图像进行分类,但在 flow_from_directory 命令中出现目录错误。我粘贴下面的代码。如果有人能帮助我,那就太好了。
IMAGE_SIZE = [224, 224]
train_path = '/content/GlaucomaDetectionSmall.zip/Train'
valid_path = '/content/GlaucomaDetectionSmall.zip/Test'
# add preprocessing layer to the front of VGG
resnet50 = ResNet50(input_shape=IMAGE_SIZE + [3], weights='imagenet', include_top=False)
# don't train existing weights
for layer in resnet50.layers:
layer.trainable = False
# useful for getting number of classes
folders = glob('/content/GlaucomaDetectionSmall.zip/Train/*')
# our layers - you can add more if you want
x = Flatten()(resnet50.output)
# x = Dense(1000, activation='relu')(x)
prediction = Dense(len(folders), activation='softmax')(x)
# create a model object
model = Model(inputs=resnet50.input, outputs=prediction)
# view the structure of the model
model.summary()
# tell the model what cost and optimization method to use
model.compile(
loss='categorical_crossentropy',
optimizer='adam',
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(**train_path**,
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')
test_set = test_datagen.flow_from_directory(**valid_path**,
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')
错误:[Errno 20] 不是目录:“/content/GlaucomaDetectionSmall.zip/Train”
I am running a ResNet50 pre-trained model for classifying glaucoma and non-glaucoma images but getting an error of directory in the flow_from_directory command. I am pasting the code below. If someone can help me, it would be great.
IMAGE_SIZE = [224, 224]
train_path = '/content/GlaucomaDetectionSmall.zip/Train'
valid_path = '/content/GlaucomaDetectionSmall.zip/Test'
# add preprocessing layer to the front of VGG
resnet50 = ResNet50(input_shape=IMAGE_SIZE + [3], weights='imagenet', include_top=False)
# don't train existing weights
for layer in resnet50.layers:
layer.trainable = False
# useful for getting number of classes
folders = glob('/content/GlaucomaDetectionSmall.zip/Train/*')
# our layers - you can add more if you want
x = Flatten()(resnet50.output)
# x = Dense(1000, activation='relu')(x)
prediction = Dense(len(folders), activation='softmax')(x)
# create a model object
model = Model(inputs=resnet50.input, outputs=prediction)
# view the structure of the model
model.summary()
# tell the model what cost and optimization method to use
model.compile(
loss='categorical_crossentropy',
optimizer='adam',
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(**train_path**,
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')
test_set = test_datagen.flow_from_directory(**valid_path**,
target_size = (224, 224),
batch_size = 32,
class_mode = 'categorical')
Error: [Errno 20] Not a directory: '/content/GlaucomaDetectionSmall.zip/Train'
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论