Keras中inception v3的预处理功能

Preprocessing function of inception v3 in Keras

这是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。

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

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

  3. 是的。另请参阅此线程和 Marcins 的回答: