mobilenet_v2
数据集下载
下载ILSVRC2012验证集到datasets/ILSVRC2012_img_val_with_subdir目录下, 数据集的图片采用带有子目录的摆放方式, 因此不需要额外的标签文件。
模型转换
使用model_transform.py接口将原模型转换为mobilenet_v2.mlir模型, 并通过run_calibration.py接口获得mobilenet_v2_cali_table。具体使用方法请参照“用户界面”章节。tpu层的INT8模型则通过下方的命令获得,运行完命令后会获得一个名为mobilenet_v2_bm1684x_int8_sym_tpu.mlir的中间文件,接下来我们将用该文件进行INT8对称量化模型的精度验证:
# INT8 对称量化模型
$ model_deploy.py \
--mlir mobilenet_v2.mlir \
--quantize INT8 \
--calibration_table mobilenet_v2_cali_table \
--chip bm1684x \
--test_input mobilenet_v2_in_f32.npz \
--test_reference mobilenet_v2_top_outputs.npz \
--tolerance 0.95,0.69 \
--model mobilenet_v2_int8.bmodel
精度验证
使用model_eval.py接口进行精度验证:
# F32 模型精度验证
$ model_eval.py \
--model_file mobilenet_v2.mlir \
--count 50000 \
--dataset_type imagenet \
--postprocess_type topx \
--dataset datasets/ILSVRC2012_img_val_with_subdir
# INT8 对称量化模型精度验证
$ model_eval.py \
--model_file mobilenet_v2_bm1684x_int8_sym_tpu.mlir \
--count 50000 \
--dataset_type imagenet \
--postprocess_type topx \
--dataset datasets/ILSVRC2012_img_val_with_subdir
F32模型与INT8对称量化模型的精度验证结果如下:
# mobilenet_v2.mlir精度验证结果
2022/11/08 01:30:29 - INFO : idx:50000, top1:0.710, top5:0.899
INFO:root:idx:50000, top1:0.710, top5:0.899
# mobilenet_v2_bm1684x_int8_sym_tpu.mlir精度验证结果
2022/11/08 05:43:27 - INFO : idx:50000, top1:0.702, top5:0.895
INFO:root:idx:50000, top1:0.702, top5:0.895
yolov5s
数据集下载
下载COCO2017验证集到datasets/val2017目录下, 该目录下即包含5000张用于验证的图片。对应的标签文件instances_val2017.json下载到datasets目录下。
模型转换
转换流程与mobilenet_v2相似。
精度验证
使用model_eval.py接口进行精度验证:
# F32 模型精度验证
$ model_eval.py \
--model_file yolov5s.mlir \
--count 5000 \
--dataset_type coco \
--postprocess_type coco_mAP \
--coco_annotation datasets/instances_val2017.json \
--dataset datasets/val2017
# INT8 对称量化模型精度验证
$ model_eval.py \
--model_file yolov5s_bm1684x_int8_sym_tpu.mlir \
--count 5000 \
--dataset_type coco \
--postprocess_type coco_mAP \
--coco_annotation datasets/instances_val2017.json \
--dataset datasets/val2017
F32模型与INT8对称量化模型的精度验证结果如下:
# yolov5s.mlir精度验证结果
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.369
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.561
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.393
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.217
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.422
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.470
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.300
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.502
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.542
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.359
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.602
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.670
# yolov5s_bm1684x_int8_sym_tpu.mlir精度验证结果
Average Precision (AP) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.337
Average Precision (AP) @[ IoU=0.50 | area= all | maxDets=100 ] = 0.544
Average Precision (AP) @[ IoU=0.75 | area= all | maxDets=100 ] = 0.365
Average Precision (AP) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.196
Average Precision (AP) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.382
Average Precision (AP) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.432
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 1 ] = 0.281
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets= 10 ] = 0.473
Average Recall (AR) @[ IoU=0.50:0.95 | area= all | maxDets=100 ] = 0.514
Average Recall (AR) @[ IoU=0.50:0.95 | area= small | maxDets=100 ] = 0.337
Average Recall (AR) @[ IoU=0.50:0.95 | area=medium | maxDets=100 ] = 0.566
Average Recall (AR) @[ IoU=0.50:0.95 | area= large | maxDets=100 ] = 0.636