Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Normalization in VGG preprocess #3

Closed
QiuJueqin opened this issue Jan 14, 2022 · 1 comment
Closed

Normalization in VGG preprocess #3

QiuJueqin opened this issue Jan 14, 2022 · 1 comment

Comments

@QiuJueqin
Copy link

Hi, as stated in torchvision page, the input to torchvision's pretrained VGG should be RGB format and normalized by mean=[0.485, 0.456, 0.406] and std=[0.229, 0.224, 0.225].

However in your code, RGB image is converted to BGR format and normalized by mean=[103.939, 116.779, 123.680] and std=[1.0, 1.0, 1.0]:

HEP/utils.py

Lines 219 to 229 in c0188bb

def vgg_preprocess(batch):
tensor_type = type(batch.data)
(r, g, b) = torch.chunk(batch, 3, dim=1)
batch = torch.cat((b, g, r), dim=1) # convert RGB to BGR
batch = batch * 255 # * 0.5 [-1, 1] -> [0, 255]
mean = tensor_type(batch.data.size()).cuda()
mean[:, 0, :, :] = 103.939
mean[:, 1, :, :] = 116.779
mean[:, 2, :, :] = 123.680
batch = batch.sub(Variable(mean)) # subtract mean
return batch

Should this be fixed?

@fengzhang427
Copy link
Owner

It‘s just an empirical trick, you can try other normalization methods.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants