pythontensorflowopencvpython-imaging-librarymobilenet

How dose the MobileNet in Tensorflow preprocess input


When we use some famous CNN deep neural networks such as MobileNet, it is recommended to preprocess an image before feeding it into the network. I found a sample code that uses MobileNet. In this code, the preprocess on the image is done by the following code in TensorFlow 2.7.0:

tf.keras.applications.mobilenet.preprocess_input(image)

I need to preprocess the input image only using PIL and OpenCV in python. Therefore, I need to know the procedure of MobileNet preprocesses in TensorFlow. I will be grateful to guide.


Solution

  • As already stated here:

    [...] mobilenet.preprocess_input will scale input pixels between -1 and 1.

    As already mentioned, you could also check out the source code itself. With opencv, you would just use cv2.resize(*) and cv2.normalize(*).