google-research / big_transfer

Official repository for the "Big Transfer (BiT): General Visual Representation Learning" paper.
https://arxiv.org/abs/1912.11370
Apache License 2.0
1.5k stars 175 forks source link

Clarity on range normalization of inputs #16

Closed hari-aindra closed 4 years ago

hari-aindra commented 4 years ago

Normalization range for input to the network is not clearly defined.

The tutorial says it should be normalized to the range 0-1 here features['image'] = tf.cast(features['image'], tf.float32) / 255.0

The training code on the other hand normalizes it to -1 to +1 here im = (im - 127.5) / 127.5

Among these, which is the correct one?

akolesnikoff commented 4 years ago

The correct scaling depends on where you download the model from. Originally, all BiT models were trained with the [-1, 1] scaling and expect such scaling as input.

However, there is one exception: if you download BiT model from https://tfhub.dev, then the expected scaling is [0, 1], as tensorflow hub enforces such convention. If I am not mistaken, in this repository, TF2 colab is the only example, that uses hub models and, thus, expects [0, 1] scaling.

hari-aindra commented 4 years ago

That solves the issue. Thanks

hari-aindra commented 4 years ago

Do the tensor-hub model with 0-1 scaling have same performance(Accuracy) as of the original BIT models ?

lucasb-eyer commented 4 years ago

Yes, they are exactly the same models and just do the conversion internally.