MXNet port of SSD: Single Shot MultiBox Object Detector. Reimplementation of
Latest commit 3e130bd Nov 17, 2016 @zhreshold add numbers to README

SSD: Single Shot MultiBox Object Detector

SSD is an unified framework for object detection with a single network.

You can use the code to train/evaluate/test for object detection task.


This is a re-implementation of original SSD which is based on caffe. The official repository is available here. The arXiv paper is available here.

This example is intended for reproducing the nice detector while fully utilize the remarkable traits of MXNet.

  • The model is fully compatible with caffe version.
  • Model converter from caffe is available, I'll release it once I can convert any symbol other than VGG16.
  • The result is almost identical to the original version. However, due to different non-maximum suppression Implementation, the results might differ slightly.

Demo results

demo1 demo2 demo3


Model Training data Test data mAP
VGG16_reduced 300x300 VOC07+12 trainval VOC07 test 71.57


Model GPU CUDNN Batch-size FPS*
VGG16_reduced 300x300 TITAN X(Maxwell) v5.1 16 95
VGG16_reduced 300x300 TITAN X(Maxwell) v5.1 8 95
VGG16_reduced 300x300 TITAN X(Maxwell) v5.1 1 64
VGG16_reduced 300x300 TITAN X(Maxwell) N/A 8 36
VGG16_reduced 300x300 TITAN X(Maxwell) N/A 1 28
  • Forward time only, data loading and drawing excluded.

Getting started

  • You will need python modules: easydict, cv2, matplotlib and numpy. You can install them via pip or package manegers, such as apt-get:
sudo apt-get install python-opencv python-matplotlib python-numpy
sudo pip install easydict
  • Clone this repo:
# if you don't have git, install it via apt or homebrew/yum based on your system
sudo apt-get install git
# cd where you would like to clone this repo
cd ~
git clone --recursive
# make sure you clone this with --recursive
# if not done correctly or you are using downloaded repo, pull them all via:
# git submodule update --recursive --init
cd mxnet-ssd/mxnet
  • Build MXNet: cd $REPO_ROOT/mxnet. Follow the official instructions here.
# for Ubuntu/Debian
cp make/ ./
# modify it if necessary

Remember to enable CUDA if you want to be able to train, since CPU training is insanely slow. Using CUDNN is optional, it's not fully tested but should be fine.

Try the demo

  • Download the pretrained model:, and extract to model/ directory. (This model is converted from VGG_VOC0712_SSD_300x300_iter_60000.caffemodel provided by paper author).
  • Run
# cd /path/to/mxnet-ssd
# play with examples:
python --epoch 0 --images ./data/demo/dog.jpg --thresh 0.5
  • Check python --help for more options.

Train the model

This example only covers training on Pascal VOC dataset. Other datasets should be easily supported by adding subclass derived from class Imdb in dataset/ See example of dataset/ for details.

  • Download the converted pretrained vgg16_reduced model here, unzip .param and .json files into model/ directory by default.
  • Download the PASCAL VOC dataset, skip this step if you already have one.
cd /path/to/where_you_store_datasets/
# Extract the data.
tar -xvf VOCtrainval_11-May-2012.tar
tar -xvf VOCtrainval_06-Nov-2007.tar
tar -xvf VOCtest_06-Nov-2007.tar
  • We are goint to use trainval set in VOC2007/2012 as a common strategy. The suggested directory structure is to store VOC2007 and VOC2012 directories in the same VOCdevkit folder.
  • Then link VOCdevkit folder to data/VOCdevkit by default:
ln -s /path/to/VOCdevkit /path/to/this_example/data/VOCdevkit

Use hard link instead of copy could save us a bit disk space.

  • Start training:
  • By default, this example will use batch-size=32 and learning_rate=0.002. You might need to change the parameters a bit if you have different configurations. Check python --help for more training options. For example, if you have 4 GPUs, use:
# note that a perfect training parameter set is yet to be discovered for multi-gpu
python --gpus 0,1,2,3 --batch-size 128 --lr 0.0005
  • Memory usage: MXNet is very memory efficient, training on VGG16_reduced model with batch-size 32 takes around 4684MB without CUDNN.

Evalute trained model

Again, currently we only support evaluation on PASCAL VOC Use:

# cd /path/to/mxnet-ssd
python --gpus 0,1 --batch-size 128 --epoch 0

Convert model to deploy mode

This simply removes all loss layers, and attach a layer for merging results and non-maximum suppression. Useful when loading python symbol is not available.

# cd /path/to/mxnet-ssd
python --num-class 20