Home

Awesome

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: