首页 文章

Keras中初始v3的预处理功能

提问于
浏览
5

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

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

1. Why there is no mean subtraction?

2. Why there is no RGB to BGR?

3. Mapping between [-1,1] is normal for this model?

这是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 回答

相关问题