【发布时间】:2020-12-02 10:31:37
【问题描述】:
我正在尝试使用 ResNet50 将图像分类为 6 个类别的模型,并且我想在使用它们训练 ResNet50 模型之前减少图像的维度。为此,我开始使用 keras 中的模型创建 ResNet50 模型:
ResNet = ResNet50(
include_top= None, weights='imagenet', input_tensor=None, input_shape=([64, 109, 3]),
pooling=None, classes=6)
然后我创建了一个包含 ResNet50 的顺序模型,但在使用 ResNet50 之前添加了一些用于分类的最终层以及用于降维的第一层: (关于输入形状:我使用的图像尺寸为 128x217,3 用于 ResNet 需要的通道)
model = models.Sequential()
model.add(GlobalAveragePooling2D(input_shape = ([128, 217, 3])))
model.add(ResNet)
model.add(GlobalAveragePooling2D())
model.add(Dense(units=512, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(units=256, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(units=6, activation='softmax'))
但这不起作用,因为第一次全局平均池化后的维度与 Resnet 中的输入形状不匹配,我得到的错误是:
WARNING:tensorflow:Model was constructed with shape (None, 64, 109, 3) for input Tensor("input_6:0", shape=(None, 64, 109, 3), dtype=float32), but it was called on an input with incompatible shape (None, 3).
ValueError: Input 0 of layer conv1_pad is incompatible with the layer: expected ndim=4, found ndim=2. Full shape received: [None, 3]
我想我明白问题出在哪里,但我不知道如何解决它,因为 (None, 3) 不是 ResNet50 的有效输入形状。我怎样才能解决这个问题?谢谢!:)
【问题讨论】:
标签: python tensorflow keras neural-network conv-neural-network