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?
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.