Skip to content

Latest commit

 

History

History

ssd

SSD Based on MindCV Backbones

SSD: Single Shot MultiBox Detector

Introduction

SSD is an single-staged object detector. It discretizes the output space of bounding boxes into a set of default boxes over different aspect ratios and scales per feature map location, and combines predictions from multi-scale feature maps to detect objects with various sizes. At prediction time, SSD generates scores for the presence of each object category in each default box and produces adjustments to the box to better match the object shape.

Figure 1. Architecture of SSD [1]

In this example, by leveraging the multi-scale feature extraction of MindCV, we demonstrate that using backbones from MindCV much simplifies the implementation of SSD.

Configurations

Here, we provide three configurations of SSD.

  • Using MobileNetV2 as the backbone and the original detector described in the paper.
  • Using ResNet50 as the backbone with a FPN and a shared-weight-based detector.
  • Using MobileNetV3 as the backbone and the original detector described in the paper.

Dataset

We train and test SSD using COCO 2017 Dataset. The dataset contains

  • 118000 images about 18 GB for training, and
  • 5000 images about 1 GB for testing.

Quick Start

Preparation

  1. Clone MindCV repository by running
git clone https://github.com/mindspore-lab/mindcv.git
  1. Install dependencies as shown here.

  2. Download COCO 2017 Dataset, prepare the dataset as follows.

.
└─cocodataset
  ├─annotations
    ├─instance_train2017.json
    └─instance_val2017.json
  ├─val2017
  └─train2017

Run the following commands to preprocess the dataset and convert it to MindRecord format for reducing preprocessing time during training and testing.

cd mindcv  # change directory to the root of MindCV repository
python examples/det/ssd/create_data.py coco --data_path [root of COCO 2017 Dataset] --out_path [directory for storing MindRecord files]

Specify the path of the preprocessed dataset at keyword data_dir in the config file.

  1. Download the pretrained backbone weights from the table below, and specify the path to the backbone weights at keyword backbone_ckpt_path in the config file.
MobileNetV2 ResNet50 MobileNetV3
backbone weights backbone weights backbone weights

Train

It is highly recommended to use distributed training for this SSD implementation.

For distributed training using msrun, simply run

cd mindcv  # change directory to the root of MindCV repository
msrun --bind_core=True --worker_num [# of devices] python examples/det/ssd/train.py --config [the path to the config file]

For example, if train SSD distributively with the MobileNetV2 configuration on 8 devices, run

cd mindcv  # change directory to the root of MindCV repository
msrun --bind_core=True --worker_num 8 python examples/det/ssd/train.py --config examples/det/ssd/ssd_mobilenetv2.yaml

For distributed training with Ascend rank table, configure ascend8p.sh as follows

#!/bin/bash
export DEVICE_NUM=8
export RANK_SIZE=8
export RANK_TABLE_FILE="./hccl_8p_01234567_127.0.0.1.json"

for ((i = 0; i < ${DEVICE_NUM}; i++)); do
    export DEVICE_ID=$i
    export RANK_ID=$i
    echo "Launching rank: ${RANK_ID}, device: ${DEVICE_ID}"
    if [ $i -eq 0 ]; then
      echo 'i am 0'
      python examples/det/ssd/train.py --config [the path to the config file] &> ./train.log &
    else
      echo 'not 0'
      python -u examples/det/ssd/train.py --config [the path to the config file] &> /dev/null &
    fi
done

and start training by running

cd mindcv  # change directory to the root of MindCV repository
bash ascend8p.sh

For single-device training, please run

cd mindcv  # change directory to the root of MindCV repository
python examples/det/ssd/train.py --config [the path to the config file]

Test

For testing the trained model, first specify the path to the model checkpoint at keyword ckpt_path in the config file, then run

cd mindcv  # change directory to the root of MindCV repository
python examples/det/ssd/eval.py --config [the path to the config file]

For example, for testing SSD with the MobileNetV2 configuration, run

cd mindcv  # change directory to the root of MindCV repository
python examples/det/ssd/eval.py --config examples/det/ssd/ssd_mobilenetv2.yaml

Performance

Here are the performance resutls and the pretrained model weights for each configuration.

Configuration Mixed Precision mAP Config Download
MobileNetV2 O2 23.2 yaml weights
ResNet50 with FPN O3 38.3 yaml weights
MobileNetV3 O2 23.8 yaml weights

References

[1] Liu, W., Anguelov, D., Erhan, D., Szegedy, C., Reed, S., Fu, C. Y., & Berg, A. C. (2016). SSD: Single Shot Multibox Detector. In Computer Vision–ECCV 2016: 14th European Conference, Amsterdam, The Netherlands, October 11–14, 2016, Proceedings, Part I 14 (pp. 21-37). Springer International Publishing.