rcmalli / keras-vggface

VGGFace implementation with Keras Framework
MIT License
928 stars 416 forks source link

Possible mean subtraction error #62

Open vvigilante opened 4 years ago

vvigilante commented 4 years ago

Here we see the preprocessing from the official source: https://github.com/keras-team/keras-preprocessing/blob/master/keras_preprocessing/image/utils.py The means are: (131.0912, 103.8827, 91.4953)

while in this repository we have

            x_temp[..., 0] -= 91.4953
            x_temp[..., 1] -= 103.8827
            x_temp[..., 2] -= 131.0912

It appears to me that both sources (this repository and the official source) use RGB channel order, so they should use the same order for the means.

The official order makes sense, because there is more red (131) than blue (91), and this appears right for face images.

Am I missing something or is this an error? Thank you for your response! Vincenzo

james-oldfield commented 4 years ago

@vvigilante right before this the RGB image seems to be converted first to BGR via

x_temp = x_temp[..., ::-1]

https://github.com/rcmalli/keras-vggface/blob/master/keras_vggface/utils.py#L44

So x_temp[..., 2] now correctly refers to the R channel, from which we subtract the larger mean. So this code indeed appears correct. Does this sound about right?

vvigilante commented 4 years ago

Ok, thank you, then my error is about the channel order: the model is trained with BGR channel order.