Skip to content

Convert resnet trained in caffe to pytorch model. (group norm resnet is provided too)

Notifications You must be signed in to change notification settings

ruotianluo/pytorch-resnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pytorch-resnet

This repository contains codes for converting resnet50,101,152 trained in caffe to pytorch model.

First, you need to have pycaffe and pytorch. Secondly, you should download the caffe models from https://github.com/KaimingHe/deep-residual-networks. Put them in data folder.

Then,

python convert.py --mode caffe

or

python convert.py --mode pth

The models generated by convert.py --mode caffe expect different preprocessing than the other models in the PyTorch model zoo. Images should be in BGR format in the range [0, 255], and the following BGR values should then be subtracted from each pixel: [103.939, 116.779, 123.68].

The models generated by convert.py --mode pth expect RGB image ranging [0, 1]. You can use standard trn.Normalize([0.485, 0.456, 0.406],[0.229, 0.224, 0.225]).

Converted models (converted from convert.py --mode caffe, used in my pytorch-faster-rcnn repo)

resnet50-caffe: https://drive.google.com/open?id=0B7fNdx_jAqhtbllXbWxMVEdZclE

resnet101-caffe: https://drive.google.com/open?id=0B7fNdx_jAqhtaXZ4aWppWV96czg

resnet152-caffe: https://drive.google.com/open?id=0B7fNdx_jAqhtMXU1N0VTZkN1dHc

Converted models (converted from convert.py --mode pth, used in my neuraltalk2-pytorch repo)

resnet50: https://drive.google.com/uc?export=download&id=0B7fNdx_jAqhtam1MSTNSYXVYZ2s

resnet101: https://drive.google.com/uc?export=download&id=0B7fNdx_jAqhtSmdCNDVOVVdINWs

resnet152: https://drive.google.com/uc?export=download&id=0B7fNdx_jAqhtckNGQ2FLd25fa3c

Note

This model is different from what's in pytorch model zoo. Although you can actually load the parameters into the pytorch resnet, the strucuture of caffe resnet and torch resnet are slightly different. The structure is defined in the resnet.py. (The file is almost identical to what's in torchvision, with only some slight changes.)

Acknowledgement

A large part of the code is borrowed from https://github.com/ry/tensorflow-resnet


pytorch-resnet-gn

Convert group norm pretrained model to pytorch.

Requirement: torchvision 0.3

python convert_gn --layers 50 --mode pth

layers can be 50 and 101, mode can be pth or caffe. mode defines what you expect as input.

The converted checkpoint gets:

  • Resnet50+GN: Prec@1 75.716 Prec@5 92.596
  • Resnet101+GN: Prec@1 77.046 Prec@5 93.438

About

Convert resnet trained in caffe to pytorch model. (group norm resnet is provided too)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages