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

Add BN-Inception #2

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open

Add BN-Inception #2

wants to merge 17 commits into from

Conversation

yjxiong
Copy link

@yjxiong yjxiong commented Jun 16, 2017

This PR adds support for BN-Inception. The model architecture is from the paper

Batch Normalization: Accelerating Deep Network Training by Reducing Internal Covariate Shift, Ioeff et. al.

Since Google didn't release trained weights of this architecture, we trained it by ourselves on ImageNet ILSVRC12 train data. It produces 92.1% top-5 accuracy on the single center crops, almost the save as reported in the original paper.

The model is not based on Tensorflow but translated from Caffe. But I feel it is still worth to provide it to other users.

@Cadene
Copy link
Owner

Cadene commented Jun 16, 2017

Thank you for your PR!

In a near futur, may I add it to https://github.com/Cadene/pretrained-models.pytorch ?
(you will be cited as a contributor, if I do so)

@yjxiong
Copy link
Author

yjxiong commented Jun 16, 2017

Sure, with pleasure.

@yjxiong
Copy link
Author

yjxiong commented Jun 16, 2017

As a side note, this BN-Inception model takes input in the range of (0~255) .

So only mean subtraction should be used in preprocessing. This is different from ResNet models provided by Facebook guys, which take input in the range of (0~1). I think it is worth to note this when listing it.

@Cadene
Copy link
Owner

Cadene commented Jun 16, 2017

Yes sure.

What is the exact transforms you used to evaluate your model ? Something like this?

 normalize = transforms.Normalize(mean=[127.5, 127.5, 127.5],
                                     std=[1, 1, 1])
transforms.Compose([
transforms.RandomSizedCrop(224),
            transforms.RandomHorizontalFlip(),
            transforms.ToTensor(),
            normalize
])

And do you know the accuracy top1/top5 on imagenet valset ?

Thanks

@yjxiong
Copy link
Author

yjxiong commented Jun 16, 2017

Good point. Since it's from Caffe, it uses mean of [104, 117, 128] and std of 1. Also, the input must be in BGR channels. Other transformations are the same, i.e. center crop for validation and random crop for training.

@Cadene
Copy link
Owner

Cadene commented Jun 16, 2017

I will give a try asap. Thanks ;)

@Cadene
Copy link
Owner

Cadene commented Jun 23, 2017

@yjxiong I encounter the following error when loading the pretrained parameters: Is it still working for you?

>>> model=BNInception(model_path='./bn_inception.yaml')
Downloading: "http://yjxiong.me/others/bn_inception-9f5701afb96c8044.pth" to /home/cadene/.torch/models/bn_inception-9f5701afb96c8044.pth
100%|██████████████████████████████████████████████████████████████████████████| 5712/5712 [00:00<00:00, 36264.90it/s]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "pytorch_load.py", line 34, in __init__
    self.load_state_dict(torch.utils.model_zoo.load_url('http://yjxiong.me/others/bn_inception-9f5701afb96c8044.pth'))
  File "/home/cadene/anaconda3/lib/python3.5/site-packages/torch/utils/model_zoo.py", line 56, in load_url
    _download_url_to_file(url, cached_file, hash_prefix)
  File "/home/cadene/anaconda3/lib/python3.5/site-packages/torch/utils/model_zoo.py", line 84, in _download_url_to_file
    .format(hash_prefix, digest))
RuntimeError: invalid hash value (expected "9f5701afb96c8044", got "c36041d6fc5c910cd3055b2117800dd9ce1fd9084e4c820ba1db97fd1491ee0e")

@yjxiong
Copy link
Author

yjxiong commented Jul 16, 2017

Hey there!

Sorry to reply so late. I have identified the issue. It is related to the file extension limit of Azure web services. I have reconfigured the server. Now it should works as expected. Please try again installing the model.

Thanks!

@Cadene
Copy link
Owner

Cadene commented Jul 16, 2017

Cool, I will give it a try tomorrow and will let you know ;)

@Cadene
Copy link
Owner

Cadene commented Jul 17, 2017

I just evaluated it on imagenet validation set, it works!
I got Accuracy@1 = 73.522 and Accuracy@5 = 91.560

What is the version of this implementation of BN Inception ?
https://arxiv.org/pdf/1502.03167.pdf (figure 3)

@yjxiong
Copy link
Author

yjxiong commented Jul 18, 2017

Hi @Cadene ,

Thanks for the testing. The model is implementing the one in Figure 5 of the paper. In Caffe we got 92.14% accuracy with it on the Val set. There might be some slight differences between the two frameworks. I guess the performance you got is quite reasonable. So please go ahead to release it to the community.

@bnu-wangxun
Copy link

Thanks very much for your great work. I have successfully used the pretrained model in my research. But I have found a problem, though this model can be successfully loaded by pytorch 0.2.0 and 0.3.0. But when we want to finetune the model, results under different version of Pytorch is very different.
In my experiment, I found python 3.5.2 and pytroch 0.2.03 will give regular result, which will be 10% higher than pytorch0.3.0 in my experiments on rank@1 for image retrieval.

@bnu-wangxun
Copy link

@yjxiong So, I want to ask you the version of python, torchvision and pytorch you used in tranferring the model from caffe.

@bnu-wangxun
Copy link

PS: Both version of pytorch can successfully load your model, I have see into the value fo the weight. Both are same, and the forward output is the same.

@poppingcode
Copy link

do you have the architecture of BNInception?
I want change a part of architecture of BNInception, so that I can train pre-training model as you are--.
then use pre-training model by pytorch.
thanks!!!

@yjxiong
Copy link
Author

yjxiong commented Apr 4, 2018

@poppingcode The architecture is the one described in the original batch normalization paper.

@kovalepskaia
Copy link

@yjxiong when I test model with RGB, it appears error as below:
RuntimeError: Error(s) in loading state_dict for BNInception:

Please give your pytorch version that you used to train

@shivansh2524
Copy link

Hi,
Can you also add weights for Places365 dataset for bn-inception model?
Thanks.

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

Successfully merging this pull request may close these issues.

6 participants