ResNet50 目录问题

发布于 2025-01-11 21:49:51 字数 2012 浏览 0 评论 0原文

我正在运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文