This repository has been archived by the owner on Nov 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Support SSD f32/int8 evaluation on COCO dataset #14646
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ remarkable traits of MXNet. | |
Due to the permission issue, this example is maintained in this [repository](/~https://github.com/zhreshold/mxnet-ssd) separately. You can use the link regarding specific per example [issues](/~https://github.com/zhreshold/mxnet-ssd/issues). | ||
|
||
### What's new | ||
* Support training and inference on COCO dataset. Int8 inference achieves 0.253 mAP on CPU with MKL-DNN backend, which is a comparable accuracy to FP32 (0.2552 mAP). | ||
* Support uint8 inference on CPU with MKL-DNN backend. Uint8 inference achieves 0.8364 mAP, which is a comparable accuracy to FP32 (0.8366 mAP). | ||
* Added live camera capture and detection display (run with --camera flag). Example: | ||
`./demo.py --camera --cpu --frame-resize 0.5` | ||
|
@@ -119,7 +120,7 @@ You can use `./demo.py --camera` to use a video capture device with opencv such | |
will open a window that will display the camera output together with the detections. You can play | ||
with the detection threshold to get more or less detections. | ||
|
||
### Train the model | ||
### Train the model on VOC | ||
* Note that we recommend to use gluon-cv to train the model, please refer to [gluon-cv ssd](https://gluon-cv.mxnet.io/build/examples_detection/train_ssd_voc.html). | ||
This example only covers training on Pascal VOC dataset. Other datasets should | ||
be easily supported by adding subclass derived from class `Imdb` in `dataset/imdb.py`. | ||
|
@@ -166,16 +167,53 @@ Check `python train.py --help` for more training options. For example, if you ha | |
python train.py --gpus 0,1,2,3 --batch-size 32 | ||
``` | ||
|
||
### Train the model on COCO | ||
* Download the COCO2014 dataset, skip this step if you already have one. | ||
``` | ||
cd /path/to/where_you_store_datasets/ | ||
wget http://images.cocodataset.org/zips/train2014.zip | ||
wget http://images.cocodataset.org/zips/val2014.zip | ||
wget http://images.cocodataset.org/annotations/annotations_trainval2014.zip | ||
# Extract the data. | ||
unzip train2014.zip | ||
unzip val2014.zip | ||
unzip annotations_trainval2014.zip | ||
``` | ||
* We are going to use `train2014,valminusminival2014` set in COCO2014 for training and `minival2014` for evaluation as a common strategy. | ||
* Then link `COCO2014` folder to `data/coco` by default: | ||
``` | ||
ln -s /path/to/COCO2014 /path/to/incubator-mxnet/example/ssd/data/coco | ||
``` | ||
Use hard link instead of copy could save us a bit disk space. | ||
* Create packed binary file for faster training: | ||
``` | ||
# cd /path/to/incubator-mxnet/example/ssd | ||
bash tools/prepare_coco.sh | ||
# or if you are using windows | ||
python tools/prepare_dataset.py --dataset coco --set train2014,valminusminival2014 --target ./data/train.lst --root ./data/coco | ||
python tools/prepare_dataset.py --dataset coco --set minival2014 --target ./data/val.lst --root ./data/coco --no-shuffle | ||
``` | ||
* Start training: | ||
``` | ||
# cd /path/to/incubator-mxnet/example/ssd | ||
python train.py --label-width=560 --num-class=80 --class-names=./dataset/names/coco_label --pretrained="" --num-example=117265 --batch-size=64 | ||
``` | ||
|
||
### Evalute trained model | ||
Make sure you have val.rec as validation dataset. It's the same one as used in training. Use: | ||
``` | ||
# cd /path/to/incubator-mxnet/example/ssd | ||
python evaluate.py --gpus 0,1 --batch-size 128 --epoch 0 | ||
|
||
# Evaluate on COCO dataset | ||
python evaluate.py --gpus 0,1 --batch-size 128 --epoch 0 --num-class=80 --class-names=./dataset/names/mscoco.names | ||
``` | ||
|
||
### Quantize model | ||
|
||
Follow the [Train instructions](/~https://github.com/apache/incubator-mxnet/tree/master/example/ssd#train-the-model) to train a FP32 `SSD-VGG16_reduced_300x300` model based on Pascal VOC dataset. You can also download our [SSD-VGG16 pre-trained model](http://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/models/ssd_vgg16_reduced_300-dd479559.zip) and [packed binary data](http://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/ssd-val-fc19a535.zip). Create `model` and `data` directories if they're not exist, extract the zip files, then rename the uncompressed files as follows (eg, rename `ssd-val-fc19a535.idx` to `val.idx`, `ssd-val-fc19a535.lst` to `val.lst`, `ssd-val-fc19a535.rec` to `val.rec`, `ssd_vgg16_reduced_300-dd479559.params` to `ssd_vgg16_reduced_300-0000.params`, `ssd_vgg16_reduced_300-symbol-dd479559.json` to `ssd_vgg16_reduced_300-symbol.json`.) | ||
To quantize a model on VOC dataset, follow the [Train instructions](/~https://github.com/apache/incubator-mxnet/tree/master/example/ssd#train-the-model-on-VOC) to train a FP32 `SSD-VGG16_reduced_300x300` model based on Pascal VOC dataset. You can also download our [SSD-VGG16 pre-trained model](http://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/models/ssd_vgg16_reduced_300-dd479559.zip) and [packed binary data](http://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/ssd-val-fc19a535.zip). Create `model` and `data` directories if they're not exist, extract the zip files, then rename the uncompressed files as follows (eg, rename `ssd-val-fc19a535.idx` to `val.idx`, `ssd-val-fc19a535.lst` to `val.lst`, `ssd-val-fc19a535.rec` to `val.rec`, `ssd_vgg16_reduced_300-dd479559.params` to `ssd_vgg16_reduced_300-0000.params`, `ssd_vgg16_reduced_300-symbol-dd479559.json` to `ssd_vgg16_reduced_300-symbol.json`.) | ||
|
||
To quantize a model on COCO dataset, follow the [Train instructions](/~https://github.com/apache/incubator-mxnet/tree/master/example/ssd#train-the-model-on-COCO) to train a FP32 `SSD-VGG16_reduced_300x300` model based on COCO dataset. You can also download our [SSD-VGG16 pre-trained model](http://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/models/ssd_vgg16_reduced_300-7fedd4ad.zip) and [packed binary data](http://apache-mxnet.s3-accelerate.dualstack.amazonaws.com/gluon/dataset/ssd_coco-val-e91096e8.zip). Create `model` and `data` directories if they're not exist, extract the zip files, then rename the uncompressed files as follows (eg, rename `ssd_coco-val-e91096e8.idx` to `val.idx`, `ssd_coco-val-e91096e8.lst` to `val.lst`, `ssd_coco-val-e91096e8.rec` to `val.rec`, `ssd_vgg16_reduced_300-7fedd4ad.params` to `ssd_vgg16_reduced_300-0000.params`, `ssd_vgg16_reduced_300-symbol-7fedd4ad.json` to `ssd_vgg16_reduced_300-symbol.json`.) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what's the difference between two paragrams of VOC and COCO? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. different link |
||
``` | ||
data/ | ||
|
@@ -199,12 +237,20 @@ After quantization, INT8 models will be saved in `model/` dictionary. Use the f | |
# USE MKLDNN AS SUBGRAPH BACKEND | ||
export MXNET_SUBGRAPH_BACKEND=MKLDNN | ||
|
||
# Launch FP32 Inference | ||
# Launch FP32 Inference on VOC dataset | ||
python evaluate.py --cpu --num-batch 10 --batch-size 224 --deploy --prefix=./model/ssd_ | ||
|
||
# Launch INT8 Inference | ||
# Launch INT8 Inference on VOC dataset | ||
python evaluate.py --cpu --num-batch 10 --batch-size 224 --deploy --prefix=./model/cqssd_ | ||
|
||
# Launch FP32 Inference on COCO dataset | ||
|
||
python evaluate.py --cpu --num-batch 10 --batch-size 224 --deploy --prefix=./model/ssd_ --num-class=80 --class-names=./dataset/names/mscoco.names | ||
|
||
# Launch INT8 Inference on COCO dataset | ||
|
||
python evaluate.py --cpu --num-batch 10 --batch-size 224 --deploy --prefix=./model/cqssd_ --num-class=80 --class-names=./dataset/names/mscoco.names | ||
|
||
# Launch dummy data Inference | ||
python benchmark_score.py --deploy --prefix=./model/ssd_ | ||
python benchmark_score.py --deploy --prefix=./model/cqssd_ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
modify this sentence since we already support COCO now :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok