Why do I have to substract 0.5 and multiply 2 to preprocess an image before loading it into and Inception_v1 model?


I want to use a .trt file to make inference. I am using the “preprocessing” of this Git: tf_to_trt_image_classification

So the image has been loaded, converted into an array of type FP32, then normalized (dividing by 255.0). But why is it needed to substract 0.5 and then multiply by 2?

Thank you


This is model-dependent procedure.
The pre-processing try to normalize input image into range [-1,1].

To normalize the signal into [-1,1] has some benefit in setting the parameter.
But not all the model takes [-1, 1] data as input. Some may just use data in range [0, 255] directly.
This depends on what kind of data the model is training on.


1 Like