V3 start preprocessing function in Keras
This is a v3 start preprocessing feature in Keras. It is completely different from the preprocessing of other models.
def preprocess_input(x):
x /= 255.
x -= 0.5
x *= 2.
return x
1. Why is there no mean subtraction?
2. Why is there no RGB for BGR?
3. Is the mapping between [-1,1] normal for this model?
and this is the VGG and ResNet preprocessing feature in Keras:
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
Also Caffe models use mean subtraction and RGB for BGR.
source to share
-
The initial model was trained using the preprocess function you specified. Therefore your images should do this function and not one for VGG / ResNet. No mean subtraction is required. See also this thread: https://github.com/fchollet/keras/issues/5416 .
-
The original GoogleNet doc refers to RGB images, not BGR. VGG, on the other hand, was trained using Caffe, while Caffe uses OpenCV to load images that use BGR by default.
-
Yes. See also this thread, and Marcins answer: Should I subtract the imagenet model precomputation in the original_v3 model inception_v3.py keras?
source to share