推理场景使用实例
下面对推理benchmark工具支持的几种模型类型分别进行举例说明。
Vision类型
- AlexNet模型
- 将工具运行脚本benchmark.x86_64、模型OM文件、数据集、精度统计脚本vision_metric.py等相关文件上传到服务器的同一路径下(如“/home/work”)。
- 进入“/home/work”,执行如下命令运行benchmark工具。
./benchmark.x86_64 -model_type=vision -batch_size=1 -device_id=1 -om_path=./alexnet.om -input_width=224 -input_height=224 -input_text_path=./ImageNet128.info -useDvpp=true
若显示如下信息,说明运行成功。从显示信息可以看到吞吐率和时延信息。同时在result文件夹也会生成记录这些信息的文件perf_vision_batchsize_1_device_1.txt。[INFO][Preprocess] Init SUCCESS [INFO][DataManager] Init SUCCESS [INFO][Inference] Init SUCCESS [INFO][PostProcess] Init SUCCESS [INFO][Vision] Create stream SUCCESS [INFO][Vision] Dvpp init resource SUCCESS [INFO][Vision] Init SUCCESS [INFO][PostProcess] CurSampleNum is 1 [INFO][PostProcess] CurSampleNum is 2 ... [INFO][PostProcess] CurSampleNum is 127 -----------------Performance Summary------------------ [e2e] throughputRate: 66.3689, latency: 1913.55 [data read] throughputRate: 7504.14, moduleLatency: 0.13326 [preprocess] throughputRate: 327.251, moduleLatency: 3.05576 [infer] throughputRate: 156.237, Interface throughputRate: 178.117, moduleLatency: 6.40864 [post] throughputRate: 156.084, moduleLatency: 6.4068 ----------------------------------------------------------- [INFO][Vision] DeInit SUCCESS [INFO][Preprocess] DeInit SUCCESS [INFO][Inference] DeInit SUCCESS [INFO][DataManager] DeInit SUCCESS [INFO][PostProcess] Deinit SUCCESS
同时在“result/dumpOutput”下生成各数据的推理结果文件(与各数据同名的txt文件)。
- 执行如下命令计算并生成精度结果文件,该文件记录模型的TOP-1至TOP-5精度。
python3 vision_metric.py ./result/dumpOutput ./HiAIAnnotations ./ result.json
参数
含义
./result/dumpOutput
2生成的推理结果文件所在路径。
./HiAIAnnotations
真实结果文件所在路径。用户根据实际路径替换。
./ result.json
生成的精度结果文件存放路径和精度结果文件的名称(如result.json),用户可以自定义。
精度结果文件信息显示示例如下:{"title": "Overall statistical evaluation", "value": [{"key": "Number of images", "value": "127"}, {"key": "Number of classes", "value": "1000"}, {"key": "Top1 accuracy", "value": "27.56%"}, {"key": "Top2 accuracy", "value": "39.37%"}, {"key": "Top3 accuracy", "value": "45.67%"}, {"key": "Top4 accuracy", "value": "47.24%"}, {"key": "Top5 accuracy", "value": "50.39%"}]}
- YoloV3 TensorFlow模型
- 将工具运行脚本benchmark.x86_64、模型OM文件、数据集、后处理脚本bin_to_predict.py和精度统计脚本map_calculate.py等相关文件上传到服务器的同一路径下(如“/home/work”)。
- 进入“/home/work”,执行如下命令运行benchmark工具。
./benchmark.x86_64 -model_type=vision -batch_size=1 -device_id=0 -om_path=./yolov3_bs1.om -input_text_path=./yolo_tf.info -input_width=416 -input_height=416 -useDvpp=false -output_binary=true
若显示如下信息,说明运行成功。从显示信息可以看到吞吐率和时延信息。同时在result文件夹也会生成记录这些信息的文件perf_vision_batchsize_1_device_0.txt。
[INFO][Preprocess] Init SUCCESS [INFO][DataManager] Init SUCCESS [INFO][Inference] Init SUCCESS [INFO][PostProcess] Init SUCCESS [INFO][Vision] Create stream SUCCESS [INFO][Vision] Dvpp init resource SUCCESS [INFO][Vision] Init SUCCESS [INFO][PostProcess] CurSampleNum is 1 [INFO][PostProcess] CurSampleNum is 2 ... [INFO][PostProcess] CurSampleNum is 35504 -----------------Performance Summary------------------ [e2e] throughputRate: 38.251, lantency: 928186 [data read] throughputRate: 61.9421, moduleLatency: 16.1441 [preprocess] throughputRate: 39.3065, moduleLatency: 25.4411 [infer] throughputRate: 38.3595, Interface throughputRate: 72.4677, moduleLatency: 11.0464 [post] throughputRate: 38.3588, moduleLatency: 26.0696 ----------------------------------------------------------- [INFO][Vision] DeInit SUCCESS [INFO][Preprocess] DeInit SUCCESS [INFO][Inference] DeInit SUCCESS [INFO][DataManager] DeInit SUCCESS [INFO][PostProcess] Deinit SUCCESS
同时在“result/dumpOutput”下生成各数据的推理结果文件(与各数据同名的bin文件)。
- 执行如下命令将2的推理结果bin文件转换为txt文件。
python3 bin_to_predict.py --bin_data_path ./result/dumpOutput --test_annotation ./yolo_tf.info --det_results_path ./detection-results --coco_class_names ./coco.names --voc_class_names ./voc.names --net_input_width 416 --net_input_height 416
参数
说明
--bin_data_path
2生成的推理结果文件所在的路径。
--test_annotation
模型对应的数据集。
--det_results_path
bin文件转换为txt文件后结果保存的路径。
--coco_class_names
coco数据集所在的路径。
--voc_class_names
VOC数据集所在的路径。
--net_input_width
模型的输入宽度。
--net_input_height
模型的输入高度。
- 执行如下命令根据3推理结果和真实结果计算出精度mAP值,并保存在result_yolo.txt文件中(用户可以自定义文件名)。
python3 map_calculate.py --label_path ./ground-truth/ --npu_txt_path ./detection-results -na -np > result_yolo.txt
其中--label_path为真实结果文件所在的路径;--npu_txt_path为3生成的txt文件所在的路径。
查看结果,显示示例如下:
45.82% = aeroplane AP 52.68% = bicycle AP 34.51% = bird AP 16.42% = boat AP 22.11% = bottle AP 61.43% = bus AP 49.49% = car AP 24.56% = cat AP 18.98% = chair AP 23.94% = cow AP 42.61% = diningtable AP 35.86% = dog AP 45.38% = horse AP 48.54% = motorbike AP 34.51% = person AP 14.64% = pottedplant AP 19.08% = sheep AP 33.47% = sofa AP 63.26% = train AP 34.28% = tvmonitor AP mAP = 36.08%
NMT类型
- 将工具运行脚本benchmark.x86_64、模型OM文件、数据集、精度统计脚本nmt_metric.py等相关文件上传到服务器的同一路径下(如“/home/work”)。
- 进入“/home/work”,执行如下命令运行benchmark工具。
./benchmark.x86_64 -model_type=nmt -batch_size=1 -device_id=0 -om_path=./nmt_tf_bs1.om -input_text_path=./tst2013.en -input_vocab=./vocab.en -ref_vocab=./vocab.vi
若显示如下信息,说明运行成功。从显示信息可以看到吞吐率和时延信息,同时在result文件夹也会生成记录这些信息的文件perf_nmt_batchsize_1_device_0.txt。
[INFO][Preprocess] Init SUCCESS [INFO][DataManager] Init SUCCESS [INFO][Inference] Init SUCCESS [INFO][PostProcess] Init SUCCESS [INFO][NmtPreprocess] Init SUCCESS [INFO][PostProcess] CurSampleNum is 1 [INFO][PostProcess] CurSampleNum is 2 ... [INFO][PostProcess] CurSampleNum is 1268 -----------------Performance Summary------------------ [e2e] throughputRate: 9.86887, latency: 128485 [data read] throughputRate: 93946.8, moduleLatency: 0.0106443 [preprocess] throughputRate: 3310.05, moduleLatency: 0.30211 [infer] throughputRate: 639.599, Interface throughputRate: 644.313, moduleLatency: 100.057 [post] throughputRate: 9.99372, moduleLatency: 100.063 ----------------------------------------------------------- [INFO][NmtPreprocess] DeInit SUCCESS [INFO][Preprocess] DeInit SUCCESS [INFO][Inference] DeInit SUCCESS [INFO][DataManager] DeInit SUCCESS [INFO][PostProcess] Deinit SUCCESS
同时在result文件夹中会生成推理结果文件nmt_output_file.txt。
- 执行如下命令根据2中生成的翻译结果和人工翻译结果计算出精度。
python3 nmt_metric.py ./tst2013.vi ./result/nmt_output_file.txt > nmt.txt
其中./tst2013.vi为人工翻译结果文件所在路径,./result/nmt_output_file.txt为2中生成的翻译结果文件所在路径,nmt.txt为精度结果保存的文件名(用户可以自定义文件名)。
查看结果,显示示例如下:
bleu: 0.56
Widedeep类型
- 将工具运行脚本benchmark.x86_64、模型OM文件、数据集等相关文件上传到服务器的同一路径下(如“/home/work”)。
在benchmark工具所在目录下需要有权重文件occupation_embedding_weights.bin。
- 进入“/home/work”,执行如下命令运行benchmark工具。
./benchmark.x86_64 -model_type=widedeep -batch_size=1 -device_id=1 -om_path=./widedeep_tf_bs1.om -input_text_path=./adult.test
若显示如下信息,说明运行成功。从显示信息可以看到吞吐率和时延信息,同时在result文件夹也会生成记录这些信息的文件perf_widedeep_batchsize_1_device_1.txt。
[INFO][Preprocess] Init SUCCESS [INFO][DataManager] Init SUCCESS [INFO][Inference] Init SUCCESS [INFO][PostProcess] Init SUCCESS [INFO][WidePreProcess] Init SUCCESS [INFO][DeepPreprocess] Init SUCCESS [INFO][PostProcess] CurSampleNum is 1 [INFO][PostProcess] CurSampleNum is 2 ... [INFO][PostProcess] CurSampleNum is 16281 -----------------Performance Summary------------------ [e2e] throughputRate: 1107.93, latency: 14695 [data read] throughputRate: 152354, moduleLatency: 0.00656366 [wide preprocess] throughputRate: 151969, moduleLatency: 0.00658028 [deep preprocess] throughputRate: 6317.22, moduleLatency: 0.158297 [infer] throughputRate: 1214.36, Interface throughputRate: 2857.56, moduleLatency: 0.813056 [post] throughputRate: 1214.34, moduleLatency: 0.823495 ----------------------------------------------------------- [INFO][WidePreProcess] DeInit SUCCESS [INFO][DeepPreprocess] DeInit SUCCESS [INFO][Preprocess] DeInit SUCCESS [INFO][Inference] DeInit SUCCESS [INFO][DataManager] DeInit SUCCESS [INFO][PostProcess] Deinit SUCCESS
此外,还会在result文件夹下生成精度结果文件widedeep_outputfile.txt。精度结果文件显示信息示例如下:
rightCount: 7241 totalCount: 16281 accuracy: 0.444752
参数
含义
rightCount
预测正确的数据个数。
totalCount
数据集中的数据总数。
accuracy
精度,公式为rightCount/totalCount。
YOLOCaffe类型
以YoloV3 caffe模型为例进行说明:
- 将工具运行脚本benchmark.x86_64、模型OM文件、数据集、后处理脚本yolo_caffe_postprocess.py和精度统计脚本map_calculate.py等相关文件上传到服务器的同一路径下(如“/home/work”)。
- 进入“/home/work”,执行如下命令运行benchmark工具。
./benchmark.x86_64 -model_type=yolocaffe -batch_size=1 -device_id=0 -om_path=./yolov3_bs1.om -input_width=416 -input_height=416 -input_text_path=./test_VOC2007.info -useDvpp=false -output_binary=true
若显示如下信息,说明运行成功。从显示信息可以看到吞吐率和时延信息,同时在result文件夹也会生成记录这些信息的文件perf_yolocaffe_batchsize_1_device_0.txt。
[INFO][Preprocess] Init SUCCESS [INFO][DataManager] Init SUCCESS [INFO][Inference] Init SUCCESS [INFO][PostProcess] Init SUCCESS [INFO][Vision] Create stream SUCCESS [INFO][Vision] Dvpp init resource SUCCESS [INFO][Vision] Init SUCCESS [INFO][PostProcess] CurSampleNum is 1 [INFO][PostProcess] CurSampleNum is 2 ... [INFO][PostProcess] CurSampleNum is 4952 -----------------Performance Summary------------------ [e2e] throughputRate: 63.5358, latency: 77940.4 [data read] throughputRate: 3452.21, moduleLatency: 0.28967 [preprocess] throughputRate: 2257.39, moduleLatency: 0.442989 [infer] throughputRate: 71.5616, Interface throughputRate: 91.2882, moduleLatency: 6.87263 [post] throughputRate: 64.5317, moduleLatency: 15.4963 ----------------------------------------------------------- [INFO][Vision] DeInit SUCCESS [INFO][Preprocess] DeInit SUCCESS [INFO][Inference] DeInit SUCCESS [INFO][DataManager] DeInit SUCCESS [INFO][PostProcess] Deinit SUCCESS
同时在“result/dumpOutput”下生成各数据的推理结果文件(与各数据同名的两份bin文件)。
- 执行如下命令将2的推理结果bin文件转换为txt文件。
python3 yolo_caffe_postprocess.py --bin_data_path ./result/dumpOutput --test_annotation ./test_VOC2007.info --det_results_path ./detection-results --coco_class_names ./coco.names --voc_class_names ./voc.names --net_input_width 416 --net_input_height 416
- 执行如下命令根据3的推理结果和真实结果计算出精度mAP值。
python3 map_calculate.py --label_path ./ground-truth/ --npu_txt_path ./detection-results -na -np
其中--label_path为真实结果文件所在的路径;--npu_txt_path为3生成的txt文件所在的路径。
显示示例如下:
86.82% = aeroplane AP 81.21% = bicycle AP 72.86% = bird AP 51.86% = boat AP 70.65% = bottle AP 92.49% = bus AP 80.39% = car AP 86.77% = cat AP 53.64% = chair AP 55.40% = cow AP 68.55% = diningtable AP 81.80% = dog AP 88.01% = horse AP 84.77% = motorbike AP 85.07% = person AP 43.31% = pottedplant AP 67.76% = sheep AP 73.35% = sofa AP 81.66% = train AP 73.00% = tvmonitor AP mAP = 73.97%
Bert类型
以Bert_base模型为例进行说明:
- 将工具运行脚本benchmark.x86_64、模型OM文件、数据集、精度统计脚本bert_metric.py等相关文件上传到服务器的同一路径下(如“/home/work”)。
- 进入“/home/work”,执行如下命令运行benchmark工具。
./benchmark.x86_64 -model_type=bert -batch_size=1 -device_id=0 -om_path=./bert_base_bs1.om -input_text_path=./MrpcData.info
若显示如下信息,说明运行成功。从显示信息可以看到吞吐率和时延信息,同时在result文件夹也会生成记录这些信息的文件perf_bert_batchsize_1_device_0.txt。
[INFO][Preprocess] Init SUCCESS [INFO][DataManager] Init SUCCESS [INFO][Inference] Init SUCCESS [INFO][PostProcess] Init SUCCESS [INFO][BertPreprocess] Init SUCCESS [INFO][PostProcess] CurSampleNum is 1 [INFO][PostProcess] CurSampleNum is 2 ... [INFO][PostProcess] CurSampleNum is 3668 -----------------Performance Summary------------------ [e2e] throughputRate: 238.919, latency: 4.18551 [data read] throughputRate: 15699.5, moduleLatency: 0.0636963 [preprocess] throughputRate: 796.15, moduleLatency: 1.25604 [infer] throughputRate: 82.1084, Interface throughputRate: 87.6803, moduleLatency: 12.1488 [post] throughputRate: 82.1079, moduleLatency: 12.1791 ----------------------------------------------------------- [INFO][BertPreprocess] DeInit SUCCESS [INFO][Preprocess] DeInit SUCCESS [INFO][Inference] DeInit SUCCESS [INFO][DataManager] DeInit SUCCESS [INFO][PostProcess] Deinit SUCCESS
同时在“result/dumpOutput”下生成各数据的推理结果文件(与各数据同名的txt文件)。
- 执行如下命令计算精度。
python3 bert_metric.py ./data.txt ./result/dumpOutput ./ result_BERT_Base.txt
参数
含义
./data.txt
真实结果文件所在的路径。
./result/dumpOutput
2中生成的推理结果文件。
./ result_BERT_Base.txt
生成的精度结果文件存放路径和精度结果文件的名称(如result_BERT_Base.txt),用户可以自定义。
查看结果,显示示例如下:
rightNum: 3041 toatlNum: 3668 rightRate: 0.829062159214831
参数
含义
rightNum
预测正确的数据个数。
toatlNum
数据集中的数据总数。
rightRate
精度,公式为rightNum/toatlNum。
NLP类型
以Transform模型为例进行说明:
- 将工具运行脚本benchmark.x86_64、模型OM文件、数据集、后处理脚本transform_tf_bin2de.py等相关文件上传到服务器的同一路径下(如“/home/work”)。
- 进入“/home/work”,执行如下命令运行benchmark工具。
./benchmark.x86_64 -model_type=nlp -batch_size=1 -device_id=3 -om_path=./transformer_bs1.om -input_text_path=./transform_3003.info -output_binary=true
若显示如下信息,说明运行成功。从显示信息可以看到吞吐率和时延信息,同时在result文件夹也会生成记录这些信息的文件perf_nlp_batchsize_1_device_3.txt。
[INFO][Preprocess] Init SUCCESS [INFO][DataManager] Init SUCCESS [INFO][Inference] Init SUCCESS [INFO][PostProcess] Init SUCCESS [INFO][NLPPreprocess] Init SUCCESS [INFO][PostProcess] CurSampleNum is 1 [INFO][PostProcess] CurSampleNum is 2 ... [INFO][PostProcess] CurSampleNum is 3003 -----------------Performance Summary------------------ [e2e] throughputRate: 0.173933, latency: 5749.33 [data read] throughputRate: 3248.83, moduleLatency: 0.307803 [preprocess] throughputRate: 3246.9, moduleLatency: 0.307986 [infer] throughputRate: 0.0579881, Interface throughputRate: 0.0583952, moduleLatency: 5748.3 [post] throughputRate: 0.173964, moduleLatency: 5748.31 ----------------------------------------------------------- [INFO][Preprocess] DeInit SUCCESS [INFO][Inference] DeInit SUCCESS [INFO][DataManager] DeInit SUCCESS [INFO][PostProcess] Deinit SUCCESS
同时在“result/dumpOutput”下生成各数据的推理结果文件(与各数据同名的bin文件)。
- 执行如下命令将生成的bin文件转换为翻译后的文本文件。
python3 transform_tf_bin2de.py ./result/dumpOutput ./vocab.translate_ende_wmt32k.32768.subwords ./benchmark_test
其中./result/dumpOutput为2生成的推理结果文件所在的路径;./vocab.translate_ende_wmt32k.32768.subwords为翻译词典所在的路径;./benchmark_test为生成的翻译后文件所在的路径。
- 执行如下命令根据生成的翻译后文本文件和真实的翻译结果计算出精度。
t2t-bleu --translation=./benchmark_test --reference=./newstest2014.de
其中./benchmark_test为3生成的翻译后文件所在的路径;./newstest2014.de为真实的翻译结果所在路径。
精度结果显示示例如下:
BLEU_uncased = 3.17 BLEU_cased = 2.98