-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Preprocessing for pretrained models? #39
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
Comments
yes, the mean/std normalization that is used in pytorch/examples/imagenet is what is expected. I'll document it now. |
@soumith, are you referring to this documentation -> http://pytorch.org/docs/torchvision/models.html Here is a link to the required preprocessing -> https://github.com/pytorch/examples/blob/master/imagenet/main.py#L92-L93 |
documented in the README of vision now. https://github.com/pytorch/vision/blob/master/README.rst#models |
Reply for easy reference normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406],
std=[0.229, 0.224, 0.225])
|
is it better that we can keep the mean and std inside the torchvision models? It is annoying to keep some magic numbers inside the code. |
@youkaichao this is a good point, and the pre-trained models should have something like that. |
@fmassa how about registering mean and std as a buffer? |
Registering them as a buffer is an option, but that also means that we would either need to change the way we do image normalization (which is currently handled in a transform) and do it in the model, or find a way of loading the state dict into a transform. Both solutions are backwards-incompatible, so I'm not very happy with them... |
@fmassa you can add a parameter at |
well, the good thing about torchvision models is that (almost) all of them have the same pre-processing values. Also, it's a bit more involved than that, because before one could just load the model using |
Hi, I want to extract features from pre-trained resnet pool5 and res5c layer.
|
@gursimar yes, it should be fine |
Hey @Atcold the link no longer works. I still cannot find the documentation for the pre-processing transforms used for various pre-trained models in torchvision. I think the transforms should be included with the model. Do all pretrained models in torchvision use the same pre-processing transforms as described by jianchao-li? |
The new link -> https://pytorch.org/vision/stable/models.html |
They are on the new Multi-weights API. Currently on prototype and you can read more here: vision/torchvision/prototype/models/resnet.py Line 113 in d8654bb
We plan to roll it out within the next couple of weeks on main TorchVision. We have dedicated issue for feedback. |
What kind of image preprocessing is expected for the pretrained models? I couldn't find this documented anywhere.
If I had to guess I would assume that they expect RGB images with the mean/std normalization used in fb.resnet.torch and pytorch/examples/imagenet. Is this correct?
The text was updated successfully, but these errors were encountered: