Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Preprocessing function of inception v3 in Keras

This is preprocessing function of inception v3 in Keras. It is totally different from other models preprocessing.

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?

and this is preprocessing function of VGG and ResNet 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 to BGR.

like image 657
Iman Avatar asked Jun 03 '17 06:06

Iman


People also ask

What is Inception v3 in keras?

Inception V3 is a type of Convolutional Neural Networks. It consists of many convolution and max pooling layers. Finally, it includes fully connected neural networks. However, you do not have to know its structure by heart. Keras would handle it instead of us.

How does inception v3 work?

Inception-v3 is a convolutional neural network that is 48 layers deep. You can load a pretrained version of the network trained on more than a million images from the ImageNet database [1]. The pretrained network can classify images into 1000 object categories, such as keyboard, mouse, pencil, and many animals.

What is Inception v3 Tensorflow?

Inception v3 is a convolutional neural network for assisting in image analysis and object detection, and got its start as a module for Googlenet. It is the third edition of Google's Inception Convolutional Neural Network, originally introduced during the ImageNet Recognition Challenge.

What is preprocess input in keras?

The preprocess_input function is meant to adequate your image to the format the model requires. Some models use images with values ranging from 0 to 1. Others from -1 to +1.


1 Answers

  1. The Inception model has been trained using the preprocess function that you quoted. Therefore your images have to run through that function rather than the one for VGG/ResNet. Subtracting the mean is not required. See also this thread: https://github.com/fchollet/keras/issues/5416.

  2. The original GoogleNet Paper refers to RGB images rather than BGR. VGG on the other hand was trained using Caffe, and Caffe uses OpenCV to load images which uses BGR by default.

  3. Yes. See also this thread and Marcins answer: Should I substract imagenet pretrained inception_v3 model mean value at inception_v3.py keras?

like image 186
petezurich Avatar answered Sep 27 '22 16:09

petezurich