aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorManu Mathew2020-06-19 08:47:16 -0500
committerManu Mathew2020-06-19 09:13:11 -0500
commit252247115ec2d4eb54dba496cfa94ffce94023ad (patch)
tree1ba4c6feac20fc2c116693c4f2df3c1281f081cb /docs/jacinto_ai_quantization_aware_training.md
parent9d0b3422cc0915028dd92b4d07377b3b8f45534f (diff)
downloadpytorch-mmdetection-252247115ec2d4eb54dba496cfa94ffce94023ad.tar.gz
pytorch-mmdetection-252247115ec2d4eb54dba496cfa94ffce94023ad.tar.xz
pytorch-mmdetection-252247115ec2d4eb54dba496cfa94ffce94023ad.zip
documentation added
Diffstat (limited to 'docs/jacinto_ai_quantization_aware_training.md')
-rw-r--r--docs/jacinto_ai_quantization_aware_training.md68
1 files changed, 68 insertions, 0 deletions
diff --git a/docs/jacinto_ai_quantization_aware_training.md b/docs/jacinto_ai_quantization_aware_training.md
new file mode 100644
index 00000000..56a57e08
--- /dev/null
+++ b/docs/jacinto_ai_quantization_aware_training.md
@@ -0,0 +1,68 @@
1# Jacinto-AI-MMDetection Quantization
2
3Quantization Aware Training (QAT) is often required to achieve the best acuracy for inference in fixed point.
4
5We have developed several tools to aid QAT and is provided in [PyTorch-Jacinto-AI-DevKit Main Page](https://bitbucket.itg.ti.com/projects/JACINTO-AI/repos/pytorch-jacinto-ai-devkit/browse/). Please consult the documentation on Quantization provided there to understand the internals of our implementation of QAT.
6
7## Features
8
9| | Float | 16 bit | 8bit | 4bit |
10|-------------------- |:--------:|:--------:|:--------:|:--------:|
11| Float32 training and test |✓ | | | |
12| Float16 training and test | | | | |
13| Post Training Calibration for Quantization (PTQ) | | ✓ | ✓ |✗ |
14| Quantization Aware Training (QAT) | | ✓ | ✓ |✗ |
15| Test/Accuracy evaluation of PTQ & QAT models | | ✓ | ✓ |✗ |
16
17✓ Available, ☐ In progress or partially available, ✗ TBD
18
19## Training
20
21#### Floating Point Training
22- Floating point training and testing can be done using the scripts provided in the [scripts](../../scripts) folder. Please consult [Usage/Instructions](jacinto_ai/jacinto_ai_mmdetection_usage.md) for more information.
23
24#### Quantization Aware Training
25- The following are the main tools provided for Quantization are:<br>
26 - Quantization Aware Training (QAT): QuantTrainModule<br>
27 - Post Training Calibration for Quantization (PTQ/Calibration): QuantCalibrateModule<br>
28 - Accuracy Test with Quantization: QuantTestModule<br>
29
30- After a model is created in pytorch-mmdetection, it is wrapped in one of the above modules depending on whether the current phase is QAT, PTQ or Test with Quantization.
31
32- Loading of pretrained model or saving of trained model needs slight change when wrapped with the above modules as the original model is inside the wrapper (otherwise the symbols in pretrained will not match).
33
34- QuantCalibrateModule is fast, but QuantTrainModule typically gives better accuracy. QuantTrainModule and QuantTestModule supports multiple gpus, whereas QuantCalibrateModule has the additional limitation that it doesn't support multiple gpus.
35
36- Training with QuantTrainModule is just like any other training. However using QuantCalibrateModule is a bit different in that it doesn't need backpropagation - so backpropagation is disabled when using QuantCalibrateModule.
37
38- We have derived additional classes from these modules called MMDetQuantTrainModules, MMDetQuantCalibrateModules and MMDetQuantTestModules because the forward call of models in mmdetection is a bit different. For example for tracing through the model, a forward_dummy method is used in mmdetection. Also the way arguments are passed to forward call are also a bit different.
39
40- Training can be done by using the scripts ./scripts/train_main.py or ./scripts/train_dist.py.
41
42- To enable quantization during training, the quantize flag in the config file being used must be a "truth value in Python" - i.e. a string or True or something like that. If quantize is commented out or if it is False, None etc, quantization will not be performed.
43
44## Testing
45- Test can be done by using the scripts ./scripts/test_main.py or ./scripts/test_dist.py
46
47- To enable quantization during test, the quantize flag in the config file being used must be a "truth value in Python" - i.e. a string or True or something like that. If quantize is commented out or if it is False, None etc, quantization will not be performed.
48
49## Results
50
51#### Pascal VOC2007 Dataset
52- Train on Pascal VOC 2007+2012
53- Test on Pascal VOC 2007
54
55|Dataset |Mode Arch |Backbone Model |Backbone Stride|Resolution |Acc Float|Acc 8bit Calib|Acc 8bit QAT|Model Config File |
56|--------- |---------- |----------- |-------------- |-----------|-------- |------- |---------- |---------- |
57|VOC2007 |SSD with FPN |MobileNetV2 |32 |512x512 |76.1 |75.4 |75.4 |configs/jacinto_ai/ssd_mobilenet_fpn.py|
58|VOC2007 |SSD with FPN |RegNet800MF |32 |512x512 |79.7 |79.0 |79.5 |configs/jacinto_ai/ssd_regnet_fpn.py |
59|VOC2007 |SSD with FPN |ResNet50 |32 |512x512 |80.5 |77.0 |79.5 |configs/jacinto_ai/ssd_resnet_fpn.py |
60|.
61|VOC2007 |SSD |VGG16 |32 |512x512 |79.8 | | |configs/pascal_voc/ssd512_voc0712.py |
62
63- Acc Float: MeanAP50(mAP) Accuracy in percentage in this case.
64- Acc 8bit Calib: Same metric with 8bit quantization using PTQ/Calibration
65- Acc Float: Same metric with QAT
66
67## References
68Please Refer to the [pytorch-jacinto-ai-devkit](https://git.ti.com/cgit/jacinto-ai/pytorch-jacinto-ai-devkit/about/) and its [Quantization documentation](https://git.ti.com/cgit/jacinto-ai/pytorch-jacinto-ai-devkit/about/docs/Quantization.md) for further details on the internals of these Quant Modules. \ No newline at end of file