【问题标题】:Preprocessing function of inception v3 in KerasKeras中inception v3的预处理功能
【发布时间】:2017-06-03 06:57:28
【问题描述】:

这是 Keras 中 inception v3 的预处理功能。它与其他模型的预处理完全不同。

def preprocess_input(x):
    x /= 255.
    x -= 0.5
    x *= 2.
    return x

1.为什么没有均值减法?

2。为什么没有RGB转BGR?

3。 [-1,1] 之间的映射对于这个模型是正常的吗?

这是Keras中VGG和ResNet的预处理功能:

def preprocess_input(x, data_format=None):
    if data_format is None:
        data_format = K.image_data_format()
    assert data_format in {'channels_last', 'channels_first'}

    if data_format == 'channels_first':
        # 'RGB'->'BGR'
        x = x[:, ::-1, :, :]
        # Zero-center by mean pixel

        x[:, 0, :, :] -= 103.939
        x[:, 1, :, :] -= 116.779
        x[:, 2, :, :] -= 123.68
    else:
        # 'RGB'->'BGR'
        x = x[:, :, :, ::-1]
        # Zero-center by mean pixel
        x[:, :, :, 0] -= 103.939
        x[:, :, :, 1] -= 116.779
        x[:, :, :, 2] -= 123.68
    return x

Caffe 模型也使用均值减法和 RGB 到 BGR。

【问题讨论】:

    标签: deep-learning keras keras-2


    【解决方案1】:
    1. 已使用您引用的预处理函数训练了 Inception 模型。因此,您的图像必须通过该功能而不是 VGG/ResNet 的功能。不需要减去平均值。另请参阅此线程:https://github.com/fchollet/keras/issues/5416

    2. 最初的 GoogleNet 论文指的是 RGB 图像而不是 BGR。另一方面,VGG 是使用 Caffe 训练的,Caffe 使用 OpenCV 加载默认使用 BGR 的图像。

    3. 是的。另请参阅此线程和 Marcins 回答:Should I substract imagenet pretrained inception_v3 model mean value at inception_v3.py keras?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-11-07
      • 1970-01-01
      • 2019-07-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-26
      相关资源
      最近更新 更多