【问题标题】:Changing input layer size in Keras pertained model在 Keras 相关模型中更改输入层大小
【发布时间】:2019-02-01 04:48:38
【问题描述】:

我在 Keras 中使用 Inception 模型和图像网络的预训练权重。

问题在于,根据 Keras 文档,此模型的默认输入大小为 299x299。虽然我的图像是 230 * 350,但我不想调整它们的大小,因为它会扭曲图像。所以我试图找到一种方法来改变输入层的大小。

下面是我迄今为止尝试过的代码,但是我怀疑图像净重是否被保留,因为我认为当我改变输入大小时架构会改变。

任何想法..

input = Input(shape=(230, 350, 3), name='image_input')
base_model = InceptionV3(weights='imagenet', include_top=False, input_tensor=input)

x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(64, activation='relu')(x)
predictions = Dense(1, activation='sigmoid')(x)

model = Model(inputs=input, outputs=predictions)

for layer in base_model.layers:
    layer.trainable = True

model.compile(loss='binary_crossentropy',
              optimizer=Adam(lr=0.0001),
              metrics=['accuracy'])

【问题讨论】:

  • 不幸的是我不能做作物,因为它是一个医学图像数据集(用于癌症)。如果我裁剪图像,我可能会丢失其中包含癌细胞的部分。

标签: python keras deep-learning conv-neural-network


【解决方案1】:

Inception V3 是一个fully convolutional 模型。您使用卷积编码器顶部的全局池化,因此与 299x299 的轻微偏差应该不是什么大问题。如果您的代码没有错误消息,那么这样使用它一定没问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-08
    • 2020-08-19
    • 2018-03-16
    • 2021-10-02
    • 2019-04-23
    • 2018-02-17
    • 2017-07-04
    • 1970-01-01
    相关资源
    最近更新 更多