


For image classification QAT demo in run_edgeailite_quantize.sh: 

#### Image Classification - Quantization Aware Training - MobileNetV2

python3 ./references/edgeailite/scripts/train_classification_main.py --dataset_name image_folder_classification --model_name mobilenetv2_tv_x1 \
--data_path ./data/datasets/image_folder_classification \
--pretrained https://download.pytorch.org/models/mobilenet_v2-b0353104.pth \
--batch_size 256 --quantize True --epochs 10 --lr 1e-5 --warmup_epochs 0 --evaluate_start False --save_onnx True

The QAT woks flow seems good and end in 10 epochs. But I  found exported onnx model is fp32 model rather that quantized model in 8 bits. Is there anything wrong?

The exported "model_best.onnx" is in ~/edgeai-torchvision/data/checkpoints/edgeailite/image_folder_classification/2021-12-10_16-54-34_image_folder_classification_mobilenetv2_tv_x1_resize256_crop224/training foler. 

The detail output logs are bellow:

=> optimizer type   : sgd
=> learning rate    : 1e-05
=> resize resolution: 256
=> crop resolution  : 224
=> batch size       : 256
=> total batch size : 256
=> epoch size       : 0
=> data augument    : inception
=> epochs           : 10
=> training   100.00% of 1x6...Epoch=1/10 LR=0.00001 Time=7.229 DataTime=0.363 Loss=11.665 Prec@1=0.077 Prec@5=0.308 rate=0.35 Hz, eta=0:00:00, total=0:00:17000
** validation 100.00% of 1x1...Epoch=1/10 LR=0.00001 Time=3.654 Loss=12.989 Prec@1=0.000 Prec@5=0.000 rate=3670.56 Hz, eta=0:00:00, total=0:00:00
trochscript export done.
trochscript export done.
=> training   100.00% of 1x6...Epoch=2/10 LR=0.00001 Time=3.682 DataTime=0.435 Loss=12.003 Prec@1=0.000 Prec@5=0.231 rate=0.37 Hz, eta=0:00:00, total=0:00:1600
** validation 100.00% of 1x1...Epoch=2/10 LR=0.00001 Time=3.753 Loss=13.174 Prec@1=0.000 Prec@5=0.000 rate=3689.15 Hz, eta=0:00:00, total=0:00:00
trochscript export done.
=> training   100.00% of 1x6...Epoch=3/10 LR=0.00001 Time=3.608 DataTime=0.409 Loss=10.677 Prec@1=0.077 Prec@5=0.308 rate=0.36 Hz, eta=0:00:00, total=0:00:1600
** validation 100.00% of 1x1...Epoch=3/10 LR=0.00001 Time=3.919 Loss=11.304 Prec@1=0.000 Prec@5=0.000 rate=4474.15 Hz, eta=0:00:00, total=0:00:00
trochscript export done.
=> training   100.00% of 1x6...Epoch=4/10 LR=0.00001 Time=3.162 DataTime=0.423 Loss=10.717 Prec@1=0.000 Prec@5=0.308 rate=0.43 Hz, eta=0:00:00, total=0:00:1300
** validation 100.00% of 1x1...Epoch=4/10 LR=0.00001 Time=3.833 Loss=11.181 Prec@1=0.000 Prec@5=0.000 rate=4418.72 Hz, eta=0:00:00, total=0:00:00
trochscript export done.
Freezing BN for subsequent epochs
=> training   100.00% of 1x6...Epoch=5/10 LR=0.00001 Time=3.322 DataTime=0.447 Loss=9.012 Prec@1=0.846 Prec@5=4.077 rate=0.40 Hz, eta=0:00:00, total=0:00:15000
** validation 100.00% of 1x1...Epoch=5/10 LR=0.00001 Time=3.195 Loss=5.581 Prec@1=4.000 Prec@5=18.000 rate=5503.91 Hz, eta=0:00:00, total=0:00:00
trochscript export done.
trochscript export done.
=> training   100.00% of 1x6...Epoch=6/10 LR=0.00001 Time=3.577 DataTime=0.465 Loss=2.144 Prec@1=51.769 Prec@5=78.308 rate=0.38 Hz, eta=0:00:00, total=0:00:1500
** validation 100.00% of 1x1...Epoch=6/10 LR=0.00001 Time=4.025 Loss=1.132 Prec@1=48.000 Prec@5=100.000 rate=4464.17 Hz, eta=0:00:00, total=0:00:00
trochscript export done.
trochscript export done.
Freezing ranges for subsequent epochs
=> training   100.00% of 1x6...Epoch=7/10 LR=0.00000 Time=2.781 DataTime=0.433 Loss=0.652 Prec@1=68.462 Prec@5=99.308 rate=0.51 Hz, eta=0:00:00, total=0:00:1100
** validation 100.00% of 1x1...Epoch=7/10 LR=0.00000 Time=3.790 Loss=0.769 Prec@1=64.000 Prec@5=100.000 rate=3100.15 Hz, eta=0:00:00, total=0:00:00
trochscript export done.
trochscript export done.
=> training   100.00% of 1x6...Epoch=8/10 LR=0.00000 Time=2.555 DataTime=0.414 Loss=0.584 Prec@1=68.692 Prec@5=99.846 rate=0.54 Hz, eta=0:00:00, total=0:00:1100
** validation 100.00% of 1x1...Epoch=8/10 LR=0.00000 Time=3.357 Loss=0.669 Prec@1=64.000 Prec@5=100.000 rate=3855.01 Hz, eta=0:00:00, total=0:00:00
trochscript export done.
=> training   100.00% of 1x6...Epoch=9/10 LR=0.00000 Time=2.210 DataTime=0.447 Loss=0.502 Prec@1=73.692 Prec@5=99.923 rate=0.68 Hz, eta=0:00:00, total=0:00:08000
** validation 100.00% of 1x1...Epoch=9/10 LR=0.00000 Time=3.437 Loss=0.623 Prec@1=66.000 Prec@5=100.000 rate=4344.05 Hz, eta=0:00:00, total=0:00:00
trochscript export done.
trochscript export done.
=> training   100.00% of 1x6...Epoch=10/10 LR=0.00000 Time=2.259 DataTime=0.479 Loss=0.464 Prec@1=76.154 Prec@5=99.923 rate=0.69 Hz, eta=0:00:00, total=0:00:08000
** validation 100.00% of 1x1...Epoch=10/10 LR=0.00000 Time=3.292 Loss=0.599 Prec@1=66.000 Prec@5=100.000 rate=5360.72 Hz, eta=0:00:00, total=0:00:00
trochscript export done.
/root/edgeai-torchvision/references/edgeailite/engine/train_classification.py:174: UserWarning: switching off bias calibration in validation
  warnings.warn('switching off bias calibration in validation')

