【问题标题】:How to change number of channels to fine tune VGG16 net in Keras如何更改通道数以在 Keras 中微调 VGG16 网络
【发布时间】:2018-03-18 20:48:30
【问题描述】:

我想使用自己的灰度图像微调 VGG16 模型。我知道我可以通过以下方式微调/添加我自己的顶层:

base_model = keras.applications.vgg16.VGG16(include_top=False, weights='imagenet', input_tensor=None, input_shape=(im_height,im_width,channels))

但根据documentation,仅当通道 = 3 时。 我曾想过简单地为我的图像添加两个冗余通道,但这似乎是在浪费计算/可能会使分类变得更糟。我还可以跨三个通道复制相同的图像,但我同样不确定它会如何执行。

【问题讨论】:

    标签: tensorflow keras keras-layer


    【解决方案1】:

    Keras 预训练模型已经在彩色图像上进行了训练,如果您想充分利用它们的能力,您应该使用彩色图像进行微调。但是,如果您有灰度图像,您仍然可以通过在三个通道上重复灰度图像来使用这些预训练模型。但显然,它不如使用彩色图像作为输入。

    【讨论】:

      【解决方案2】:

      VGG keras 模型使用函数:keras.applications.imagenet_utils._obtain_input_shape。 此函数是为 ImageNet 数据量身定制的,因此它强制输入通道为 3。一种可能的解决方法是复制 VGG16 模块并替换该行:

      input_shape = _obtain_input_shape(input_shape, default_size=224, min_size=48, data_format=K.image_data_format(), include_top=include_top)

      与:

      input_shape = (im_height, im_width, 1)

      附带说明,您将无法加载 ImageNet 权重,因为您的输入空间已更改并且第一层卷积将不匹配。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-09-09
        • 2017-10-13
        • 2019-06-22
        • 2020-03-15
        • 1970-01-01
        • 2017-10-07
        • 1970-01-01
        • 2016-05-01
        相关资源
        最近更新 更多