From 7f7f1fbb3b04fd80a0f050d26457a7467ab4edc1 Mon Sep 17 00:00:00 2001 From: qingqing01 Date: Mon, 17 Jun 2019 20:45:49 +0800 Subject: [PATCH] Move object_detection to ssd (#2423) * Move object_detection to ssd. --- PaddleCV/object_detection/README.md | 97 +----------------- .../{ => ssd}/object_detection/.gitignore | 0 .../{ => ssd}/object_detection/.run_ce.sh | 0 PaddleCV/ssd/object_detection/README.md | 96 +++++++++++++++++ .../{ => ssd}/object_detection/README_cn.md | 0 .../object_detection/README_quant.md | 0 PaddleCV/{ => ssd}/object_detection/_ce.py | 0 .../object_detection/data/coco/download.sh | 0 .../data/pascalvoc/create_list.py | 0 .../data/pascalvoc/download.sh | 0 .../data/pascalvoc/label_list | 0 PaddleCV/{ => ssd}/object_detection/eval.py | 0 .../object_detection/eval_coco_map.py | 0 .../{ => ssd}/object_detection/image_util.py | 0 .../object_detection/images/009943.jpg | Bin .../object_detection/images/009956.jpg | Bin .../object_detection/images/009960.jpg | Bin .../object_detection/images/009962.jpg | Bin .../images/COCO_val2014_000000000139.jpg | Bin .../images/COCO_val2014_000000000785.jpg | Bin .../images/COCO_val2014_000000000885.jpg | Bin .../images/COCO_val2014_000000142324.jpg | Bin .../images/COCO_val2014_000000144003.jpg | Bin .../images/SSD_paper_figure.jpg | Bin PaddleCV/{ => ssd}/object_detection/infer.py | 0 .../{ => ssd}/object_detection/main_quant.py | 0 .../object_detection/mobilenet_ssd.py | 0 .../pretrained/download_coco.sh | 0 .../pretrained/download_imagenet.sh | 0 PaddleCV/{ => ssd}/object_detection/reader.py | 0 PaddleCV/{ => ssd}/object_detection/train.py | 0 .../{ => ssd}/object_detection/utility.py | 0 32 files changed, 98 insertions(+), 95 deletions(-) rename PaddleCV/{ => ssd}/object_detection/.gitignore (100%) rename PaddleCV/{ => ssd}/object_detection/.run_ce.sh (100%) create mode 100644 PaddleCV/ssd/object_detection/README.md rename PaddleCV/{ => ssd}/object_detection/README_cn.md (100%) rename PaddleCV/{ => ssd}/object_detection/README_quant.md (100%) rename PaddleCV/{ => ssd}/object_detection/_ce.py (100%) rename PaddleCV/{ => ssd}/object_detection/data/coco/download.sh (100%) rename PaddleCV/{ => ssd}/object_detection/data/pascalvoc/create_list.py (100%) rename PaddleCV/{ => ssd}/object_detection/data/pascalvoc/download.sh (100%) rename PaddleCV/{ => ssd}/object_detection/data/pascalvoc/label_list (100%) rename PaddleCV/{ => ssd}/object_detection/eval.py (100%) rename PaddleCV/{ => ssd}/object_detection/eval_coco_map.py (100%) rename PaddleCV/{ => ssd}/object_detection/image_util.py (100%) rename PaddleCV/{ => ssd}/object_detection/images/009943.jpg (100%) rename PaddleCV/{ => ssd}/object_detection/images/009956.jpg (100%) rename PaddleCV/{ => ssd}/object_detection/images/009960.jpg (100%) rename PaddleCV/{ => ssd}/object_detection/images/009962.jpg (100%) rename PaddleCV/{ => ssd}/object_detection/images/COCO_val2014_000000000139.jpg (100%) rename PaddleCV/{ => ssd}/object_detection/images/COCO_val2014_000000000785.jpg (100%) rename PaddleCV/{ => ssd}/object_detection/images/COCO_val2014_000000000885.jpg (100%) rename PaddleCV/{ => ssd}/object_detection/images/COCO_val2014_000000142324.jpg (100%) rename PaddleCV/{ => ssd}/object_detection/images/COCO_val2014_000000144003.jpg (100%) rename PaddleCV/{ => ssd}/object_detection/images/SSD_paper_figure.jpg (100%) rename PaddleCV/{ => ssd}/object_detection/infer.py (100%) rename PaddleCV/{ => ssd}/object_detection/main_quant.py (100%) rename PaddleCV/{ => ssd}/object_detection/mobilenet_ssd.py (100%) rename PaddleCV/{ => ssd}/object_detection/pretrained/download_coco.sh (100%) rename PaddleCV/{ => ssd}/object_detection/pretrained/download_imagenet.sh (100%) rename PaddleCV/{ => ssd}/object_detection/reader.py (100%) rename PaddleCV/{ => ssd}/object_detection/train.py (100%) rename PaddleCV/{ => ssd}/object_detection/utility.py (100%) diff --git a/PaddleCV/object_detection/README.md b/PaddleCV/object_detection/README.md index 2466ba96..bc992d06 100644 --- a/PaddleCV/object_detection/README.md +++ b/PaddleCV/object_detection/README.md @@ -1,96 +1,3 @@ -## SSD Object Detection +## PaddlePaddle Object Detection -## Table of Contents -- [Introduction](#introduction) -- [Data Preparation](#data-preparation) -- [Train](#train) -- [Evaluate](#evaluate) -- [Infer and Visualize](#infer-and-visualize) -- [Released Model](#released-model) - -### Introduction - -[Single Shot MultiBox Detector (SSD)](https://arxiv.org/abs/1512.02325) framework for object detection can be categorized as a single stage detector. A single stage detector simplifies object detection as a regression problem, which directly predicts the bounding boxes and class probabilities without region proposal. SSD further makes improves by producing these predictions of different scales from different layers, as shown below. Six levels predictions are made in six different scale feature maps. And there are two 3x3 convolutional layers in each feature map, which predict category or a shape offset relative to the prior box(also called anchor), respectively. Thus, we get 38x38x4 + 19x19x6 + 10x10x6 + 5x5x6 + 3x3x4 + 1x1x4 = 8732 detections per class. -

-
-The Single Shot MultiBox Detector (SSD) -

- -SSD is readily pluggable into a wide variant standard convolutional network, such as VGG, ResNet, or MobileNet, which is also called base network or backbone. In this tutorial we used [MobileNet](https://arxiv.org/abs/1704.04861). - - -### Data Preparation - -Please download [PASCAL VOC dataset](http://host.robots.ox.ac.uk/pascal/VOC/) at first, skip this step if you already have one. - -```bash -cd data/pascalvoc -./download.sh -``` - -The command `download.sh` also will create training and testing file lists. - -### Train - -#### Download the Pre-trained Model. - -We provide two pre-trained models. The one is MobileNet-v1 SSD trained on COCO dataset, but removed the convolutional predictors for COCO dataset. This model can be used to initialize the models when training other datasets, like PASCAL VOC. The other pre-trained model is MobileNet-v1 trained on ImageNet 2012 dataset but removed the last weights and bias in the Fully-Connected layer. Download MobileNet-v1 SSD: - - ```bash - ./pretrained/download_coco.sh - ``` - -Declaration: the MobileNet-v1 SSD model is converted by [TensorFlow model](https://github.com/tensorflow/models/blob/f87a58cd96d45de73c9a8330a06b2ab56749a7fa/research/object_detection/g3doc/detection_model_zoo.md). - - -#### Train on PASCAL VOC - -`train.py` is the main caller of the training module. Examples of usage are shown below. - ```bash - python -u train.py --batch_size=64 --dataset='pascalvoc' --pretrained_model='pretrained/ssd_mobilenet_v1_coco/' - ``` - - Set ```export CUDA_VISIBLE_DEVICES=0,1``` to specifiy the number of GPU you want to use. - - For more help on arguments: - - ```bash - python train.py --help - ``` - -Data reader is defined in `reader.py`. All images will be resized to 300x300. In training stage, images are randomly distorted, expanded, cropped and flipped: - - distort: distort brightness, contrast, saturation, and hue. - - expand: put the original image into a larger expanded image which is initialized using image mean. - - crop: crop image with respect to different scale, aspect ratio, and overlap. - - flip: flip horizontally. - -We used RMSProp optimizer with mini-batch size 64 to train the MobileNet-SSD. The initial learning rate is 0.001, and was decayed at 40, 60, 80, 100 epochs with multiplier 0.5, 0.25, 0.1, 0.01, respectively. Weight decay is 0.00005. After 120 epochs we achieve 73.32% mAP under 11point metric. - -### Evaluate - -You can evaluate your trained model in different metrics like 11point, integral on both PASCAL VOC and COCO dataset. Note we set the default test list to the dataset's test/val list, you can use your own test list by setting ```--test_list``` args. - -`eval.py` is the main caller of the evaluating module. Examples of usage are shown below. -```bash -python eval.py --dataset='pascalvoc' --model_dir='train_pascal_model/best_model' --data_dir='data/pascalvoc' --test_list='test.txt' --ap_version='11point' --nms_threshold=0.45 -``` - -### Infer and Visualize -`infer.py` is the main caller of the inferring module. Examples of usage are shown below. -```bash -python infer.py --dataset='pascalvoc' --nms_threshold=0.45 --model_dir='train_pascal_model/best_model' --image_path='./data/pascalvoc/VOCdevkit/VOC2007/JPEGImages/009963.jpg' -``` -Below are the examples of running the inference and visualizing the model result. -

- - - -
-MobileNet-v1-SSD 300x300 Visualization Examples -

- - -### Released Model - - -| Model | Pre-trained Model | Training data | Test data | mAP | -|:------------------------:|:------------------:|:----------------:|:------------:|:----:| -|[MobileNet-v1-SSD 300x300](http://paddlemodels.bj.bcebos.com/ssd_mobilenet_v1_pascalvoc.tar.gz) | COCO MobileNet SSD | VOC07+12 trainval| VOC07 test | 73.32% | +Thanks for your attention. The object detection framework based on PaddlePaddle will be coming soon. diff --git a/PaddleCV/object_detection/.gitignore b/PaddleCV/ssd/object_detection/.gitignore similarity index 100% rename from PaddleCV/object_detection/.gitignore rename to PaddleCV/ssd/object_detection/.gitignore diff --git a/PaddleCV/object_detection/.run_ce.sh b/PaddleCV/ssd/object_detection/.run_ce.sh similarity index 100% rename from PaddleCV/object_detection/.run_ce.sh rename to PaddleCV/ssd/object_detection/.run_ce.sh diff --git a/PaddleCV/ssd/object_detection/README.md b/PaddleCV/ssd/object_detection/README.md new file mode 100644 index 00000000..2466ba96 --- /dev/null +++ b/PaddleCV/ssd/object_detection/README.md @@ -0,0 +1,96 @@ +## SSD Object Detection + +## Table of Contents +- [Introduction](#introduction) +- [Data Preparation](#data-preparation) +- [Train](#train) +- [Evaluate](#evaluate) +- [Infer and Visualize](#infer-and-visualize) +- [Released Model](#released-model) + +### Introduction + +[Single Shot MultiBox Detector (SSD)](https://arxiv.org/abs/1512.02325) framework for object detection can be categorized as a single stage detector. A single stage detector simplifies object detection as a regression problem, which directly predicts the bounding boxes and class probabilities without region proposal. SSD further makes improves by producing these predictions of different scales from different layers, as shown below. Six levels predictions are made in six different scale feature maps. And there are two 3x3 convolutional layers in each feature map, which predict category or a shape offset relative to the prior box(also called anchor), respectively. Thus, we get 38x38x4 + 19x19x6 + 10x10x6 + 5x5x6 + 3x3x4 + 1x1x4 = 8732 detections per class. +

+
+The Single Shot MultiBox Detector (SSD) +

+ +SSD is readily pluggable into a wide variant standard convolutional network, such as VGG, ResNet, or MobileNet, which is also called base network or backbone. In this tutorial we used [MobileNet](https://arxiv.org/abs/1704.04861). + + +### Data Preparation + +Please download [PASCAL VOC dataset](http://host.robots.ox.ac.uk/pascal/VOC/) at first, skip this step if you already have one. + +```bash +cd data/pascalvoc +./download.sh +``` + +The command `download.sh` also will create training and testing file lists. + +### Train + +#### Download the Pre-trained Model. + +We provide two pre-trained models. The one is MobileNet-v1 SSD trained on COCO dataset, but removed the convolutional predictors for COCO dataset. This model can be used to initialize the models when training other datasets, like PASCAL VOC. The other pre-trained model is MobileNet-v1 trained on ImageNet 2012 dataset but removed the last weights and bias in the Fully-Connected layer. Download MobileNet-v1 SSD: + + ```bash + ./pretrained/download_coco.sh + ``` + +Declaration: the MobileNet-v1 SSD model is converted by [TensorFlow model](https://github.com/tensorflow/models/blob/f87a58cd96d45de73c9a8330a06b2ab56749a7fa/research/object_detection/g3doc/detection_model_zoo.md). + + +#### Train on PASCAL VOC + +`train.py` is the main caller of the training module. Examples of usage are shown below. + ```bash + python -u train.py --batch_size=64 --dataset='pascalvoc' --pretrained_model='pretrained/ssd_mobilenet_v1_coco/' + ``` + - Set ```export CUDA_VISIBLE_DEVICES=0,1``` to specifiy the number of GPU you want to use. + - For more help on arguments: + + ```bash + python train.py --help + ``` + +Data reader is defined in `reader.py`. All images will be resized to 300x300. In training stage, images are randomly distorted, expanded, cropped and flipped: + - distort: distort brightness, contrast, saturation, and hue. + - expand: put the original image into a larger expanded image which is initialized using image mean. + - crop: crop image with respect to different scale, aspect ratio, and overlap. + - flip: flip horizontally. + +We used RMSProp optimizer with mini-batch size 64 to train the MobileNet-SSD. The initial learning rate is 0.001, and was decayed at 40, 60, 80, 100 epochs with multiplier 0.5, 0.25, 0.1, 0.01, respectively. Weight decay is 0.00005. After 120 epochs we achieve 73.32% mAP under 11point metric. + +### Evaluate + +You can evaluate your trained model in different metrics like 11point, integral on both PASCAL VOC and COCO dataset. Note we set the default test list to the dataset's test/val list, you can use your own test list by setting ```--test_list``` args. + +`eval.py` is the main caller of the evaluating module. Examples of usage are shown below. +```bash +python eval.py --dataset='pascalvoc' --model_dir='train_pascal_model/best_model' --data_dir='data/pascalvoc' --test_list='test.txt' --ap_version='11point' --nms_threshold=0.45 +``` + +### Infer and Visualize +`infer.py` is the main caller of the inferring module. Examples of usage are shown below. +```bash +python infer.py --dataset='pascalvoc' --nms_threshold=0.45 --model_dir='train_pascal_model/best_model' --image_path='./data/pascalvoc/VOCdevkit/VOC2007/JPEGImages/009963.jpg' +``` +Below are the examples of running the inference and visualizing the model result. +

+ + + +
+MobileNet-v1-SSD 300x300 Visualization Examples +

+ + +### Released Model + + +| Model | Pre-trained Model | Training data | Test data | mAP | +|:------------------------:|:------------------:|:----------------:|:------------:|:----:| +|[MobileNet-v1-SSD 300x300](http://paddlemodels.bj.bcebos.com/ssd_mobilenet_v1_pascalvoc.tar.gz) | COCO MobileNet SSD | VOC07+12 trainval| VOC07 test | 73.32% | diff --git a/PaddleCV/object_detection/README_cn.md b/PaddleCV/ssd/object_detection/README_cn.md similarity index 100% rename from PaddleCV/object_detection/README_cn.md rename to PaddleCV/ssd/object_detection/README_cn.md diff --git a/PaddleCV/object_detection/README_quant.md b/PaddleCV/ssd/object_detection/README_quant.md similarity index 100% rename from PaddleCV/object_detection/README_quant.md rename to PaddleCV/ssd/object_detection/README_quant.md diff --git a/PaddleCV/object_detection/_ce.py b/PaddleCV/ssd/object_detection/_ce.py similarity index 100% rename from PaddleCV/object_detection/_ce.py rename to PaddleCV/ssd/object_detection/_ce.py diff --git a/PaddleCV/object_detection/data/coco/download.sh b/PaddleCV/ssd/object_detection/data/coco/download.sh similarity index 100% rename from PaddleCV/object_detection/data/coco/download.sh rename to PaddleCV/ssd/object_detection/data/coco/download.sh diff --git a/PaddleCV/object_detection/data/pascalvoc/create_list.py b/PaddleCV/ssd/object_detection/data/pascalvoc/create_list.py similarity index 100% rename from PaddleCV/object_detection/data/pascalvoc/create_list.py rename to PaddleCV/ssd/object_detection/data/pascalvoc/create_list.py diff --git a/PaddleCV/object_detection/data/pascalvoc/download.sh b/PaddleCV/ssd/object_detection/data/pascalvoc/download.sh similarity index 100% rename from PaddleCV/object_detection/data/pascalvoc/download.sh rename to PaddleCV/ssd/object_detection/data/pascalvoc/download.sh diff --git a/PaddleCV/object_detection/data/pascalvoc/label_list b/PaddleCV/ssd/object_detection/data/pascalvoc/label_list similarity index 100% rename from PaddleCV/object_detection/data/pascalvoc/label_list rename to PaddleCV/ssd/object_detection/data/pascalvoc/label_list diff --git a/PaddleCV/object_detection/eval.py b/PaddleCV/ssd/object_detection/eval.py similarity index 100% rename from PaddleCV/object_detection/eval.py rename to PaddleCV/ssd/object_detection/eval.py diff --git a/PaddleCV/object_detection/eval_coco_map.py b/PaddleCV/ssd/object_detection/eval_coco_map.py similarity index 100% rename from PaddleCV/object_detection/eval_coco_map.py rename to PaddleCV/ssd/object_detection/eval_coco_map.py diff --git a/PaddleCV/object_detection/image_util.py b/PaddleCV/ssd/object_detection/image_util.py similarity index 100% rename from PaddleCV/object_detection/image_util.py rename to PaddleCV/ssd/object_detection/image_util.py diff --git a/PaddleCV/object_detection/images/009943.jpg b/PaddleCV/ssd/object_detection/images/009943.jpg similarity index 100% rename from PaddleCV/object_detection/images/009943.jpg rename to PaddleCV/ssd/object_detection/images/009943.jpg diff --git a/PaddleCV/object_detection/images/009956.jpg b/PaddleCV/ssd/object_detection/images/009956.jpg similarity index 100% rename from PaddleCV/object_detection/images/009956.jpg rename to PaddleCV/ssd/object_detection/images/009956.jpg diff --git a/PaddleCV/object_detection/images/009960.jpg b/PaddleCV/ssd/object_detection/images/009960.jpg similarity index 100% rename from PaddleCV/object_detection/images/009960.jpg rename to PaddleCV/ssd/object_detection/images/009960.jpg diff --git a/PaddleCV/object_detection/images/009962.jpg b/PaddleCV/ssd/object_detection/images/009962.jpg similarity index 100% rename from PaddleCV/object_detection/images/009962.jpg rename to PaddleCV/ssd/object_detection/images/009962.jpg diff --git a/PaddleCV/object_detection/images/COCO_val2014_000000000139.jpg b/PaddleCV/ssd/object_detection/images/COCO_val2014_000000000139.jpg similarity index 100% rename from PaddleCV/object_detection/images/COCO_val2014_000000000139.jpg rename to PaddleCV/ssd/object_detection/images/COCO_val2014_000000000139.jpg diff --git a/PaddleCV/object_detection/images/COCO_val2014_000000000785.jpg b/PaddleCV/ssd/object_detection/images/COCO_val2014_000000000785.jpg similarity index 100% rename from PaddleCV/object_detection/images/COCO_val2014_000000000785.jpg rename to PaddleCV/ssd/object_detection/images/COCO_val2014_000000000785.jpg diff --git a/PaddleCV/object_detection/images/COCO_val2014_000000000885.jpg b/PaddleCV/ssd/object_detection/images/COCO_val2014_000000000885.jpg similarity index 100% rename from PaddleCV/object_detection/images/COCO_val2014_000000000885.jpg rename to PaddleCV/ssd/object_detection/images/COCO_val2014_000000000885.jpg diff --git a/PaddleCV/object_detection/images/COCO_val2014_000000142324.jpg b/PaddleCV/ssd/object_detection/images/COCO_val2014_000000142324.jpg similarity index 100% rename from PaddleCV/object_detection/images/COCO_val2014_000000142324.jpg rename to PaddleCV/ssd/object_detection/images/COCO_val2014_000000142324.jpg diff --git a/PaddleCV/object_detection/images/COCO_val2014_000000144003.jpg b/PaddleCV/ssd/object_detection/images/COCO_val2014_000000144003.jpg similarity index 100% rename from PaddleCV/object_detection/images/COCO_val2014_000000144003.jpg rename to PaddleCV/ssd/object_detection/images/COCO_val2014_000000144003.jpg diff --git a/PaddleCV/object_detection/images/SSD_paper_figure.jpg b/PaddleCV/ssd/object_detection/images/SSD_paper_figure.jpg similarity index 100% rename from PaddleCV/object_detection/images/SSD_paper_figure.jpg rename to PaddleCV/ssd/object_detection/images/SSD_paper_figure.jpg diff --git a/PaddleCV/object_detection/infer.py b/PaddleCV/ssd/object_detection/infer.py similarity index 100% rename from PaddleCV/object_detection/infer.py rename to PaddleCV/ssd/object_detection/infer.py diff --git a/PaddleCV/object_detection/main_quant.py b/PaddleCV/ssd/object_detection/main_quant.py similarity index 100% rename from PaddleCV/object_detection/main_quant.py rename to PaddleCV/ssd/object_detection/main_quant.py diff --git a/PaddleCV/object_detection/mobilenet_ssd.py b/PaddleCV/ssd/object_detection/mobilenet_ssd.py similarity index 100% rename from PaddleCV/object_detection/mobilenet_ssd.py rename to PaddleCV/ssd/object_detection/mobilenet_ssd.py diff --git a/PaddleCV/object_detection/pretrained/download_coco.sh b/PaddleCV/ssd/object_detection/pretrained/download_coco.sh similarity index 100% rename from PaddleCV/object_detection/pretrained/download_coco.sh rename to PaddleCV/ssd/object_detection/pretrained/download_coco.sh diff --git a/PaddleCV/object_detection/pretrained/download_imagenet.sh b/PaddleCV/ssd/object_detection/pretrained/download_imagenet.sh similarity index 100% rename from PaddleCV/object_detection/pretrained/download_imagenet.sh rename to PaddleCV/ssd/object_detection/pretrained/download_imagenet.sh diff --git a/PaddleCV/object_detection/reader.py b/PaddleCV/ssd/object_detection/reader.py similarity index 100% rename from PaddleCV/object_detection/reader.py rename to PaddleCV/ssd/object_detection/reader.py diff --git a/PaddleCV/object_detection/train.py b/PaddleCV/ssd/object_detection/train.py similarity index 100% rename from PaddleCV/object_detection/train.py rename to PaddleCV/ssd/object_detection/train.py diff --git a/PaddleCV/object_detection/utility.py b/PaddleCV/ssd/object_detection/utility.py similarity index 100% rename from PaddleCV/object_detection/utility.py rename to PaddleCV/ssd/object_detection/utility.py -- GitLab