tensorflow-model-zoo.torch icon indicating copy to clipboard operation
tensorflow-model-zoo.torch copied to clipboard

Add BN-Inception

Open yjxiong opened this issue 8 years ago • 19 comments
trafficstars

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.

yjxiong avatar Jun 16 '17 06:06 yjxiong

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)

Cadene avatar Jun 16 '17 08:06 Cadene

Sure, with pleasure.

yjxiong avatar Jun 16 '17 08:06 yjxiong

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.

yjxiong avatar Jun 16 '17 08:06 yjxiong

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

Cadene avatar Jun 16 '17 08:06 Cadene

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.

yjxiong avatar Jun 16 '17 08:06 yjxiong

I will give a try asap. Thanks ;)

Cadene avatar Jun 16 '17 09:06 Cadene

@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")

Cadene avatar Jun 23 '17 13:06 Cadene

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!

yjxiong avatar Jul 16 '17 05:07 yjxiong

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

Cadene avatar Jul 16 '17 10:07 Cadene

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)

Cadene avatar Jul 17 '17 19:07 Cadene

Added to my new lib :)

https://github.com/Cadene/pretrained-models.pytorch/blob/master/pretrainedmodels/bninception.py

https://github.com/Cadene/pretrained-models.pytorch#bninception

Cadene avatar Jul 17 '17 20:07 Cadene

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.

yjxiong avatar Jul 18 '17 04:07 yjxiong

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 avatar Feb 12 '18 05:02 bnu-wangxun

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

bnu-wangxun avatar Feb 12 '18 05:02 bnu-wangxun

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.

bnu-wangxun avatar Feb 12 '18 05:02 bnu-wangxun

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!!!

poppingcode avatar Apr 04 '18 07:04 poppingcode

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

yjxiong avatar Apr 04 '18 17:04 yjxiong

@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

kovalepskaia avatar Jan 04 '19 17:01 kovalepskaia

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

shivansh2524 avatar Apr 06 '19 03:04 shivansh2524