oarriaga / face_classification

Real-time face detection and emotion/gender classification using fer2013/imdb datasets with a keras CNN model and openCV.
MIT License
5.61k stars 1.59k forks source link

Understanding the code #114

Closed j13mehul closed 5 years ago

j13mehul commented 5 years ago
def preprocess_input(x, v2=True):
    x = x.astype('float32')
    x = x / 255.0
    if v2:
        x = x - 0.5
        x = x * 2.0
    return x

I know x/255 is normalizing the image. What is the purpose of x-0.5 and x*2.0

oarriaga commented 5 years ago

Hi since the image is normalized [0, 1] you then move it to [-.5, .5] and the finally you scaled it by [-1 ,1].