Home

Awesome

Switchable Normalization for Object Detection

This repository contains the code of using Swithable Normalization (SN) in object detection, proposed by the paper "Differentiable Learning-to-Normalize via Switchable Normalization".

This is a re-implementation of the experiments presented in the above paper by using Detectron.pytorch. SN is easy to plug into different codebases. Please refer to the paper that evaluated SN in another two codebases Faster R-CNN.pytorch and fb's Caffe2 Detectron.

Update

Citation

You are encouraged to cite the following paper if you use SN in research or wish to refer to the baseline results.

@article{SwitchableNorm,
  title={Differentiable Learning-to-Normalize via Switchable Normalization},
  author={Ping Luo and Jiamin Ren and Zhanglin Peng},
  journal={arXiv:1806.10779},
  year={2018}
}

Getting Started

Use git to clone this repository:

git clone https://github.com/switchablenorms/SwitchNorm_Detection.git

Environment

The code is tested under the following configurations.

Installation & Data Preparation

Please check the Requirements, Compilation, and Data Preparation subsection in the repo Detectron.pytorch for the details of installation.

Pre-trained Models

Download the pretrained model and put them into the {repo_root}/data/pretrained_model.

ImageNet pre-trained models

The backbone models with SN pretrained on ImageNet are available in the format used by Detectron.pytorch and this repo.

* For (8,1), SN contains IN and SN without BN, as BN is the same as IN in training.

For more pretrained models with SN, please refer to the repo of switchablenorms/Switchable-Normalization. The following script converts the model trained from Switchable-Normalization into a valid format used by the detection codebase.

./scripts/convert.sh

Input arguments:

usage: convert.py [-h] [--ckpt CKPT] [--dst DST] [--use-FPN]

NOTE: The paramater keys in pretrained model checkpoint must match the keys in backbone model EXACTLY. The prefix of the backbone key in the model with FPN is Conv_Body.conv_body, while it is Conv_Body in the model without FPN. The parameters in [w/ fpn] and [w/o fpn] backbone models with SN above are the same, except for the keys. You should load the correct pretrained model according to your detection architechure.

Training

Optional arguments (see full input arguments via python tools/train_net_step.py -h):

  --dataset DATASET     Dataset to use
  --cfg CFG_FILE        Config file for training (and optionally testing)
  --bs BATCH_SIZE       Explicitly specify to overwrite the value comed from
                        cfg_file.
  --resume              resume to training on a checkpoint
  --load_ckpt LOAD_CKPT
                        checkpoint path to load
  --use_tfboard         Use tensorflow tensorboard to log training info

NOTE: There is something different about the resume mode between Detectron.pytorch and this repo. In this repo, --resume allows the training to resume from the lastest checkpoint in output_dir, which is generated in the training process automatically. You do not need to re-assign --load_ckpt. If output_dir is empty, --resume does not apply.

Evaluation

Optional arguments (see full input arguments via python tools/test_net.py -h):

  --dataset DATASET     training dataset
  --cfg CFG_FILE        optional config file
  --load_dir LOAD_DIR   path of checkpoint to load
  --load_ckpt LOAD_CKPT
                        path of checkpoint to load
  --use_tfboard         Use tensorflow tensorboard to log training info

--load_dir enables continuous evaluation when training. When --load_dir is assigned, the lastest checkpoint under this path will be evaluated, and wait for the next checkpoint exists after the current evaluation is completed. If you want to test one model once, you can load this model from --load_ckpt.

Main Results

End-to-End Faster & Mask R-CNN with SN

backbonenormtypelr schdim/gpubox APmask APdownload
R-50-C4SN-(8,32)faster2x238.07--model | boxes
R-50-FPNSN-(8,2)faster2x239.10--model | boxes
R-50-FPNSN-(8, 1)faster2x238.99--model | boxes
R-50-FPNSN-(8, 1)mask2x241.0136.12model | boxes | masks

Comparisons with BN and GN

We also implement GN by using the same codebase in this repo for reference. Several results of BN are borrowed from fb's Detectron.

backbonenormtypelr schdim/gpubox APmask APreference
R-50-C4BNfaster2x236.5--Detectron
R-50-C4^GNfaster2x237.3--
R-50-FPNBNfaster2x237.9--Detectron
R-50-FPN^GNfaster2x238.3--
R-50-FPNBNmask2x238.634.5Detectron
R-50-FPN^GNmask2x240.435.6
R-50-FPNGNmask2x240.335.7Detectron

^ reproduced results based on this repository