Skip to content
This repository has been archived by the owner on Aug 5, 2022. It is now read-only.

SSD: Single Shot MultiBox Detector

Sylwester edited this page Feb 6, 2017 · 18 revisions

Introduction

This page covers tips and usage guide for SSD in Intel® Distribution of Caffe*, It should give you a brief introduction to help you run training, inference and scoring. For more thorough explanation visit the original project website https://github.com/weiliu89/caffe/tree/ssd. Instructions on this page will be referring to this site as the original SSD website. Links to resources mentioned below can be found there.

Note: SSD currently does not work with USE_MKL2017_AS_DEFAULT_ENGINE=ON flag nor -engine MKL2017 command-line argument. The engines are already specified per layer in prototxt. Do not specify default engine when using SSD as they overwrite the per layer settings. It will change soon when we will have MKL2017 support SSD specific concat and dilated convolution layers.

Setting up

  1. Modify examples/ssd/ssdvars.sh file according to your needs and call:
source examples/ssd/ssdvars.sh
  1. Download fully convolutional reduced (atrous) VGGNet from original SSD project website and extract .caffemodel only. By default, we assume the model is stored in $CAFFE_ROOT/examples/ssd/VGGNet/.

Datasets

You can download datasets as instructed in the original SSD project github site.

VOC example

LMDB creation

download data and extract it

#### Download the data.
cd $DATAPATH/data
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtrainval_06-Nov-2007.tar
wget http://host.robots.ox.ac.uk/pascal/VOC/voc2007/VOCtest_06-Nov-2007.tar
# Extract the data.
tar -xvf VOCtrainval_11-May-2012.tar
tar -xvf VOCtrainval_06-Nov-2007.tar
tar -xvf VOCtest_06-Nov-2007.tar

Create the LMDB file

# Go to your caffe directory
cd $CAFFE_ROOT
# Create the trainval.txt, test.txt, and test_name_size.txt in data/VOC0712/
./data/VOC0712/create_list.sh
# You can modify the parameters in create_data.sh if needed.
# It will create lmdb files for trainval and test with encoded original image:
# - $DATAPATH/data/VOCdevkit/VOC0712/lmdb/VOC0712_trainval_lmdb
# - $DATAPATH/data/VOCdevkit/VOC0712/lmdb/VOC0712_test_lmdb
# and make soft links at examples/VOC0712/
./data/VOC0712/create_data.sh

Training

Train your model and evaluate

./build/tools/caffe train -solver examples/ssd/VGGNet/VOC0712/SSD_300x300/solver.prototxt \
-weights examples/ssd/VGGNet/VGG_ILSVRC_16_layers_fc_reduced.caffemodel
# It should reach 77.* mAP at 120k iterations according to the author's reports.

Scoring

All you need to do to run scoring(assuming you have LMDB) is: download and extract ONLY the pre-trained model from links at the bottom of original page, and put the *1200000.caffemodel file inside: examples/ssd/VGGNet/VOC0712/SSD_300x300/ Run the line below and wait patiently for the result:

caffe test --detection --weights=<weights file> --model=<model file> --iterations=<no of iters>

Switch --detection turns on SSD. By default it's false so when the switch does not appear in the command, classification is executed. The output should be like below, where detection_eval = XXXX is the mAP score:

I1219 11:22:03.161818 71583 caffe.cpp:155] Finetuning from models/VGGNet/VOC0712/SSD_300x300/VGG_VOC0712_SSD_300x300_iter_120000.caffemodel
I1219 11:22:03.588759 71583 net.cpp:761] Ignoring source layer mbox_loss
I1219 11:22:03.592058 71583 caffe.cpp:251] Starting Optimization
I1219 11:22:03.592092 71583 solver.cpp:294] Solving VGG_VOC0712_SSD_300x300_train
I1219 11:22:03.592097 71583 solver.cpp:295] Learning Rate Policy: multistep
I1219 11:22:04.485777 71583 solver.cpp:332] Iteration 0, loss = 1.46778
I1219 11:22:04.485929 71583 solver.cpp:433] Iteration 0, Testing net (#0)
I1219 11:22:04.491395 71583 net.cpp:693] Ignoring source layer mbox_loss
I1219 12:01:24.939699 71583 solver.cpp:546] Test net output #0: detection_eval = 0.776861
I1219 12:01:24.939939 71583 solver.cpp:337] Optimization Done.
I1219 12:01:24.939947 71583 caffe.cpp:254] Optimization Done.

Inference example based on VOC

Download models from original SSD webiste. Modify the paths in deploy.prototxt file to point to your output directory (i.e. $DATAPATH/data/VOCdevkit/VOC0712/results/VOC2007/SSD_300x300/Main) Run the below lines:

./build/examples/ssd/ssd_detect examples/ssd/VGGNet/VOC0712/SSD_300x300/deploy.prototxt \
examples/ssd/VGGNet/VOC0712/SSD_300x300/VGG_VOC0712_SSD_300x300_iter_120000.caffemodel \
examples/ssd/images.txt -out_file detected.txt

python ./tools/extra/plot_detections.py \
--labelmap-file ./data/VOC0712/labelmap_voc.prototxt \
detected.txt . --save-dir . --visualize-threshold 0.2

See the result - in caffe directory you will have a file fish-bike.jpg.png. You should see a person and a bicycle detected.

COCO example

LMDB creation

Follow instructions in $CAFFE_ROOT/data/coco/README.md They are quite complex.

Training

You should have cafemodel from Firstly section. You can run it the same way as VOC just specify different path to solver for coco.

Scoring

Download COCO model from original SSD website. Run it the same way as VOC. You should get [email protected] = 0.430362. To test [email protected] instead of default [email protected] change the overlap_threshold value in the prototxt for the MultiBoxLoss layer. The score should be for mAP@75 = 0.276951


*Other names and brands may be claimed as the property of others

Clone this wiki locally