preprocess_input() method in keras

前端 未结 3 2116
余生分开走
余生分开走 2021-01-30 10:22

I am trying out sample keras code from the below keras documentation page, https://keras.io/applications/

What preprocess_input(x)

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-30 11:25

    Keras works with batches of images. So, the first dimension is used for the number of samples (or images) you have.

    When you load a single image, you get the shape of one image, which is (size1,size2,channels).

    In order to create a batch of images, you need an additional dimension: (samples, size1,size2,channels)

    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. Others use the "caffe" style, that is not normalized, but is centered.

    From the source code, Resnet is using the caffe style.

    You don't need to worry about the internal details of preprocess_input. But ideally, you should load images with the keras functions for that (so you guarantee that the images you load are compatible with preprocess_input).

提交回复
热议问题