Home

Awesome

Convert ResNets weights from GluonCV to Tensorflow

Abstract

GluonCV released some new resnet pre-training weights and designed some new resnets (such as resnet_v1_b, resnet_v1_d, refer this for detail).

This project reproduces the resnet in glouncv by Tensorflow and attempts to convert the pre-training weights in glouncv to the Tensorflow CheckPoints. At present, we have completed the conversion of resnet50_v1_b, resnet101_v1_b, resnet50_v1_d, resnet101_v1_d, and the 1000-dimensional Logits error rate is controlled within the range of 1e-5. (We welcome you to submit PR to support more models.)

We also try to transfer these weights to object detection (using FPN as the baseline, the specific detection code we will post here.), and train on voc07trainVal (excluding voc2012 dataset), test in voc07test. The results are as follows:

Comparison

use_voc2007_metric

ModelsmAPsheephorsebicyclebottlecowsofabusdogcatpersontraindiningtableaeroplanecarpottedplanttvmonitorchairbirdboatmotorbike
Faster-RCNN resnet101_v1(original)74.6376.3586.1879.8758.7383.474.7580.0385.486.5578.2476.0770.8978.5286.2647.8076.3452.1478.0658.9078.04
FPN resnet101_v1(original)76.1474.6385.1381.6763.7982.4377.8383.0786.4585.8281.0881.0171.2280.0186.3048.0573.8956.9978.3362.9182.24
FPN resnet101_v1_d77.9878.0187.4885.3465.4284.5674.4282.9787.8787.3482.1484.4470.3280.6488.651.976.5959.3181.1967.8483.1

FPN_resnet101_v1_d is transfer from GluonCV

FPN_resnet101_v1(original) is official resnet in tensorflow/models

My Development Environment

1、python2.7 (anaconda recommend)

2、cuda9.0

3、opencv(cv2)

4、mxnet-cu90 (1.3.0)

5、tensorflow == 1.10

6、GlounCV

Download MxNet GluonCV PreTrained Weights

cd $PATH_ROOT/resnet
(modify the resnet version in the main function of download_mxnet_resnet_weights.py.)
python download_mxnet_resnet_weights.py

Convert MxNet Weights To Tensorflow CheckPoint and caculate Erros

modify the main function in gluon2TF/resnet/test_resnet.py as following, and then run it

MODEL_NAME = 'resnet101_v1d' (modify the version as u want)
Mxnet_Weights_PATH = '../mxnet_weights/resnet101_v1d-1b2b825f.params' (remember modify the path)

cal_erro(img_path='../demo_img/person.jpg',
             use_tf_ckpt=False,
             ckpt_path='../tf_ckpts/%s.ckpt' % MODEL_NAME,
             save_ckpt=True)

Just run it :

cd $PATH_ROOT/resnet
python test_resnet

caculate Erros between the converted tensorflow chenckpoints and Mxnet GluonCV Weights

modify the main function in gluon2TF/resnet/test_resnet.py as following, and then run it

MODEL_NAME = 'resnet101_v1d' (modify the version as u want)
Mxnet_Weights_PATH = '../mxnet_weights/resnet101_v1d-1b2b825f.params' (remember modify the path)

cal_erro(img_path='../demo_img/person.jpg',
             use_tf_ckpt=True,
             ckpt_path='../tf_ckpts/%s.ckpt' % MODEL_NAME,
             save_ckpt=False)

Just run it :

cd $PATH_ROOT/resnet
python test_resnet