这是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 回答
使用您引用的预处理功能训练了Inception模型 . 因此,您的图像必须通过该功能而不是VGG / ResNet的功能 . 不需要减去均值 . 另见这个帖子:https://github.com/fchollet/keras/issues/5416 .
原始GoogleNet论文指的是RGB图像而不是BGR . 另一方面,VGG使用Caffe进行训练,Caffe使用OpenCV加载默认使用BGR的图像 .
是的 . 另见这个帖子和Marcins的回答:Should I substract imagenet pretrained inception_v3 model mean value at inception_v3.py keras?