I want to use pre-trained model from PyTorch to train a faster-rcnn. And I see:
If you want to use pytorch pre-trained models, please remember to transpose images from BGR to RGB, and also use the same data transformer (minus mean and normalize) as used in pretrained model.
Does this mean I need to do the following two things?
By the way, I didn't see any code about normalizing the images with a stdv value. Is there a configuration option about this or do I need to add code in lib/roi_data_layer/minibatch.py?
Thank you!
Hi, @clavichord93 ,
Yes, to use pytorch pre-tained model, you need to make three changes:
1) convert image from BGR to RGB
2) normalize image range from [0, 255] to [0, 1]
3) use transformer:
normalize = transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
to transform the image data.
Details can be found here: http://pytorch.org/docs/master/torchvision/models.html
@jwyang Must I use transformer?
Can I simply change blob.py from
im -= pixel_means
# im = im[:, :, ::-1]
to
im -= pixel_means
im /= 255.
im /= pixel_stdvs
im = im[:, :, ::-1]
?
I find that replacing the existing code with transforms needs a lot of work.
yes, the order of commands should be:
im /= 255. # Convert range to [0,1]
im -= pixel_means # Minus mean
im /= pixel_stdens # divide by stddev
you do not need to add "im = im[:, :, ::-1]" since im from scipy.misc.imread is already RGB.
To facilitate the transfer from caffe models to pytorch models, I will make some changes to the code. Stay tuned.
I am adding im = im[:, :, ::-1] to eliminate the same statement here but yes, it is unnecessary.
I think a configuration entry for caffe model or pytorch model and an entry for pixel stdv may be a helpful method to do this :)
Yeah, that makes sense. Thanks for pointing out this!
On Thu, Dec 28, 2017 at 11:58 Zheng Qin notifications@github.com wrote:
I am adding im = im[:, :, ::-1] to eliminate the same statement here
https://github.com/jwyang/faster-rcnn.pytorch/blob/2675672f7de786d6e9b07f1f20564dd0ee35cb60/lib/roi_data_layer/minibatch.py#L73
but yes, it is unnecessary.I think a configuration entry for caffe model or pytorch model and an
entry for pixel stdv may be a helpful method to do this :)—
You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub
https://github.com/jwyang/faster-rcnn.pytorch/issues/10#issuecomment-354319993,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ADtr52HVSlDyB_f5RtoYPLllpz9PO2Mqks5tE8iigaJpZM4RORfQ
.
Following these steps, I still got 3% lower in ResNet 101 (74.3% vs 71.3%) when using pytorch pretrained resnet101. @jwyang Is this consistent with your results? Is there any new finding on why? Thanks in advance.
Most helpful comment
yes, the order of commands should be:
im /= 255. # Convert range to [0,1]
im -= pixel_means # Minus mean
im /= pixel_stdens # divide by stddev
you do not need to add "im = im[:, :, ::-1]" since im from scipy.misc.imread is already RGB.
To facilitate the transfer from caffe models to pytorch models, I will make some changes to the code. Stay tuned.