-
Notifications
You must be signed in to change notification settings - Fork 6.8k
fix ssd quantization script error #13843
Changes from 4 commits
8df9e35
84be0b9
65fb13f
482fae6
9be6603
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,7 @@ The following models have been tested on Linux systems. | |
|[Inception V3](#7)|[Gluon-CV](https://gluon-cv.mxnet.io/model_zoo/classification.html)|[Validation Dataset](http://data.mxnet.io/data/val_256_q90.rec)|76.49%/93.10% |76.38%/93% | | ||
|[ResNet152-V2](#8)|[MXNet ModelZoo](http://data.mxnet.io/models/imagenet/resnet/152-layers/)|[Validation Dataset](http://data.mxnet.io/data/val_256_q90.rec)|76.76%/93.03%|76.48%/92.96%| | ||
|[Inception-BN](#9)|[MXNet ModelZoo](http://data.mxnet.io/models/imagenet/inception-bn/)|[Validation Dataset](http://data.mxnet.io/data/val_256_q90.rec)|72.09%/90.60%|72.00%/90.53%| | ||
| [SSD-VGG](#10) | [example/ssd](https://github.com/apache/incubator-mxnet/tree/master/example/ssd) | VOC2007/2012 | 0.83 mAP | 0.82 mAP | | ||
| [SSD-VGG](#10) | [example/ssd](https://github.com/apache/incubator-mxnet/tree/master/example/ssd) | VOC2007/2012 | 0.8366 mAP | 0.8364 mAP | | ||
|
||
<h3 id='3'>ResNet50-V1</h3> | ||
|
||
|
@@ -210,40 +210,7 @@ python imagenet_inference.py --symbol-file=./model/imagenet1k-inception-bn-quant | |
|
||
<h3 id='10'>SSD-VGG</h3> | ||
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. SSD-VGG16 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. no problem, any other description in current README need udpated? |
||
|
||
Follow the [SSD example's instructions](https://github.com/apache/incubator-mxnet/tree/master/example/ssd#train-the-model) in [example/ssd](https://github.com/apache/incubator-mxnet/tree/master/example/ssd) 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). Extract the zip files, then rename the directories to `model` and `data` respectively. Then, rename the files in directories as follows. | ||
|
||
``` | ||
data/ | ||
|---val.rec | ||
|---val.lxt | ||
|---val.idx | ||
model/ | ||
|---ssd_vgg16_reduced_300.params | ||
|---ssd_vgg16_reduced_300-symbol.json | ||
``` | ||
|
||
Then, use the following command for quantization. By default, this script uses 5 batches (32 samples per batch) for naive calibration: | ||
|
||
``` | ||
python quantization.py | ||
``` | ||
|
||
After quantization, INT8 models will be saved in `model/` dictionary. Use the following command to launch inference. | ||
|
||
``` | ||
# USE MKLDNN AS SUBGRAPH BACKEND | ||
export MXNET_SUBGRAPH_BACKEND=MKLDNN | ||
|
||
# Launch FP32 Inference | ||
python evaluate.py --cpu --num-batch 10 --batch-size 224 --deploy --prefix=./model/ssd_ | ||
|
||
# Launch INT8 Inference | ||
python evaluate.py --cpu --num-batch 10 --batch-size 224 --deploy --prefix=./model/cqssd_ | ||
|
||
# Launch dummy data Inference | ||
python benchmark_score.py --deploy --prefix=./model/ssd_ | ||
python benchmark_score.py --deploy --prefix=./model/cqssd_ | ||
``` | ||
SSD model is located in [example/ssd](https://github.com/apache/incubator-mxnet/tree/master/example/ssd), follow [the insturctions](https://github.com/apache/incubator-mxnet/tree/master/example/ssd#quantize-model) to run quantized SSD model. | ||
|
||
<h3 id='11'>Custom Model</h3> | ||
|
||
|
@@ -322,4 +289,4 @@ by invoking `launch_quantize.sh`. | |
|
||
**NOTE**: | ||
- This example has only been tested on Linux systems. | ||
- Performance is expected to decrease with GPU, however the memory footprint of a quantized model is smaller. The purpose of the quantization implementation is to minimize accuracy loss when converting FP32 models to INT8. MXNet community is working on improving the performance. | ||
- Performance is expected to decrease with GPU, however the memory footprint of a quantized model is smaller. The purpose of the quantization implementation is to minimize accuracy loss when converting FP32 models to INT8. MXNet community is working on improving the performance. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,12 +119,14 @@ def save_params(fname, arg_params, aux_params, logger=None): | |
exclude_first_conv = args.exclude_first_conv | ||
excluded_sym_names = [] | ||
rgb_mean = '123,117,104' | ||
calib_layer = lambda name: name.endswith('_output') | ||
for i in range(1,19): | ||
excluded_sym_names += ['flatten'+str(i)] | ||
excluded_sym_names += ['relu4_3_cls_pred_conv', | ||
'relu7_cls_pred_conv', | ||
'relu4_3_loc_pred_conv'] | ||
'relu4_3_loc_pred_conv', | ||
'multibox_loc_pred', | ||
'concat0', | ||
'concat1'] | ||
if exclude_first_conv: | ||
excluded_sym_names += ['conv1_1'] | ||
|
||
|
@@ -156,9 +158,9 @@ def save_params(fname, arg_params, aux_params, logger=None): | |
ctx=ctx, excluded_sym_names=excluded_sym_names, | ||
calib_mode=calib_mode, calib_data=eval_iter, | ||
num_calib_examples=num_calib_batches * batch_size, | ||
calib_layer=calib_layer, quantized_dtype=args.quantized_dtype, | ||
calib_layer=None, quantized_dtype=args.quantized_dtype, | ||
label_names=(label_name,), | ||
calib_quantize_op = True, | ||
calib_quantize_op=True, | ||
logger=logger) | ||
sym_name = '%s-symbol.json' % ('./model/cqssd_vgg16_reduced_300') | ||
param_name = '%s-%04d.params' % ('./model/cqssd_vgg16_reduced_300', epoch) | ||
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. Why not remove 0000 in here instead of adding 0000 in the readme? Any special meaning for it? 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. It's a convention of mxnet. We can save different parameter files at different epochs. 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. Thanks for the explanation. Agree the change makes sense :) |
||
|
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.
SSD-VGG16