From 381cbaa7643bf93ad2ab4eb07c876132602ce9d0 Mon Sep 17 00:00:00 2001 From: zengxianglong Date: Mon, 29 Mar 2021 10:30:40 +0800 Subject: [PATCH] tf models support running fp16 mode and add models to the entrance guard --- mindspore/lite/test/models_caffe.cfg | 16 ++ mindspore/lite/test/models_caffe_fp16.cfg | 16 ++ .../lite/test/models_for_process_only.cfg | 2 + mindspore/lite/test/models_npu.cfg | 2 + mindspore/lite/test/models_onnx.cfg | 3 + mindspore/lite/test/models_onnx_fp16.cfg | 6 + mindspore/lite/test/models_tf_fp16.cfg | 9 +- mindspore/lite/test/models_tflite.cfg | 3 +- mindspore/lite/test/models_tflite_fp16.cfg | 1 + .../test/models_with_multiple_inputs_fp16.cfg | 5 + mindspore/lite/test/run_benchmark_nets.sh | 219 +++++++++--------- 11 files changed, 170 insertions(+), 112 deletions(-) diff --git a/mindspore/lite/test/models_caffe.cfg b/mindspore/lite/test/models_caffe.cfg index c12ed5ae21..9f7a76f3ba 100644 --- a/mindspore/lite/test/models_caffe.cfg +++ b/mindspore/lite/test/models_caffe.cfg @@ -92,3 +92,19 @@ ml_handpose ml_lable_model_hebing_device ml_face_sex ml_face_hat +ml_face_compare +ml_face_tracking +ml_face_beard +ml_face_age +ml_face_pose +ml_face_isface +ml_face_glasses +ml_segmentation_matting +ml_segmentation_atlanta_10 +ml_bodymask +ml_Hand_deploy +ml_hand_3d_detection +ml_hand_3d_regression +ml_ARengine23_bodypose +ml_ocr_bank_card_detection_inception +ml_ocr_bank_card_recognition_fcny diff --git a/mindspore/lite/test/models_caffe_fp16.cfg b/mindspore/lite/test/models_caffe_fp16.cfg index b767efb6a9..88f3704405 100644 --- a/mindspore/lite/test/models_caffe_fp16.cfg +++ b/mindspore/lite/test/models_caffe_fp16.cfg @@ -87,3 +87,19 @@ ml_video_edit_img_segment 3 ml_video_edit_video_segment_gauss_adaptis_part1 5 ml_handpose 175 hdc_Face_Aesthetic_MTI_Aesthetic 22 +ml_face_compare 5.5 +ml_face_tracking 2.5 +ml_face_beard 0.5 +ml_face_age 3.5 +ml_face_pose 1 +ml_face_isface 0.5 +ml_face_glasses 2.5 +# ml_segmentation_matting 26 # output value unstable +ml_segmentation_atlanta_10 5 +ml_bodymask 14 +ml_Hand_deploy 4 +ml_hand_3d_detection 12 +ml_hand_3d_regression 3 +ml_ARengine23_bodypose 56 +ml_ocr_bank_card_detection_inception 20 +ml_ocr_bank_card_recognition_fcny 0.5 diff --git a/mindspore/lite/test/models_for_process_only.cfg b/mindspore/lite/test/models_for_process_only.cfg index ba1c96b98f..3c5ef42d8b 100644 --- a/mindspore/lite/test/models_for_process_only.cfg +++ b/mindspore/lite/test/models_for_process_only.cfg @@ -22,3 +22,5 @@ quant_aware_bank_card_detection_inception.onnx quant_aware_bank_card_recognition_fcny.onnx quant_aware_identify_card_detect.onnx tiny-yolov3-11.onnx;2;1,416,416,3:1,2 +# cur acc for ml_video_edit_art_transfer is 2+% +ml_video_edit_art_transfer.onnx;3 diff --git a/mindspore/lite/test/models_npu.cfg b/mindspore/lite/test/models_npu.cfg index f379ae9081..c657bb302c 100644 --- a/mindspore/lite/test/models_npu.cfg +++ b/mindspore/lite/test/models_npu.cfg @@ -79,3 +79,5 @@ hdc_mobilenet_1w_class.onnx 20 hdc_age_medium 504 posenet_mobilenet_float_075_1_default_1.tflite 395 nasnet_mobile.tflite 1 +ml_video_edit_art_generate.onnx 0.5 +ml_video_edit_art_transfer.onnx 3 3 diff --git a/mindspore/lite/test/models_onnx.cfg b/mindspore/lite/test/models_onnx.cfg index 10bff56c02..f493a2e9e2 100644 --- a/mindspore/lite/test/models_onnx.cfg +++ b/mindspore/lite/test/models_onnx.cfg @@ -58,3 +58,6 @@ ml_edu_kit_hand_detection.onnx ml_edu_kit_hand_key_position.onnx ml_facedetector.onnx ml_ei_facedetection.onnx +ml_video_edit_art_generate.onnx +ml_location_lane_counter.onnx +# ml_location_lane_counter0.onnx diff --git a/mindspore/lite/test/models_onnx_fp16.cfg b/mindspore/lite/test/models_onnx_fp16.cfg index 64da7aa5d5..96222483c4 100644 --- a/mindspore/lite/test/models_onnx_fp16.cfg +++ b/mindspore/lite/test/models_onnx_fp16.cfg @@ -55,3 +55,9 @@ hdc_Face_Emotion_MTI_Aesthetic.onnx 144 ml_video_edit_imitate_filter.onnx 103 ml_facedetector.onnx 3 ml_ei_facedetection.onnx 2 +#ml_video_edit_art_generate.onnx #mul operator overflows, not suitable for fp16 +ml_location_lane_counter.onnx 6 +# ml_location_lane_counter0.onnx 0.5 +#The encoder an decoder model are used in ml_asr scene, both have value overflow. Not suitable for fp16. +#But added for guarding process. +encoder.onnx;1,32,83 1262 diff --git a/mindspore/lite/test/models_tf_fp16.cfg b/mindspore/lite/test/models_tf_fp16.cfg index d7f188a8c4..29a2ac0701 100644 --- a/mindspore/lite/test/models_tf_fp16.cfg +++ b/mindspore/lite/test/models_tf_fp16.cfg @@ -1,2 +1,7 @@ -decoder_step_201217_modified.pb 5;;0.5 -encoder_0111_control_flow.pb 4;1:1,44:1:1;10 +ml_vision_guide_detection1.pb 0.5 +ml_vision_guide_detection3.pb 0.5 +ml_video_edit_generate_filter.pb 2 +ml_ocr_jk.pb 0.5 +ml_ocr_latin.pb 135 +scan_hms_angle.pb 1.5 +scan_hms_detect.pb 2.5 diff --git a/mindspore/lite/test/models_tflite.cfg b/mindspore/lite/test/models_tflite.cfg index 689b431b69..655dd2396c 100644 --- a/mindspore/lite/test/models_tflite.cfg +++ b/mindspore/lite/test/models_tflite.cfg @@ -161,4 +161,5 @@ Q_landmark.tflite Q_language_model_hrmini_Q4_b4_17w.tflite Q_new_detect.tflite Q_object_scene.tflite -Q_pose.tflite \ No newline at end of file +Q_pose.tflite +ml_ei_landmark_pb2tflite.tflite diff --git a/mindspore/lite/test/models_tflite_fp16.cfg b/mindspore/lite/test/models_tflite_fp16.cfg index 562d4d73de..5ea040dae8 100644 --- a/mindspore/lite/test/models_tflite_fp16.cfg +++ b/mindspore/lite/test/models_tflite_fp16.cfg @@ -157,3 +157,4 @@ lite-model_on_device_vision_classifier_landmarks_classifier_asia_V1_1.tflite 25 lite-model_on_device_vision_classifier_landmarks_classifier_oceania_antarctica_V1_1.tflite 10 lite-model_on_device_vision_classifier_landmarks_classifier_europe_V1_1.tflite 32 lite-model_on_device_vision_classifier_landmarks_classifier_south_america_V1_1.tflite 14 +ml_ei_landmark_pb2tflite.tflite 2 diff --git a/mindspore/lite/test/models_with_multiple_inputs_fp16.cfg b/mindspore/lite/test/models_with_multiple_inputs_fp16.cfg index 167c1ec8e3..a50a151375 100644 --- a/mindspore/lite/test/models_with_multiple_inputs_fp16.cfg +++ b/mindspore/lite/test/models_with_multiple_inputs_fp16.cfg @@ -5,3 +5,8 @@ ml_video_edit_img_segment_adaptise_pb2tflite.tflite;2 0.5 ml_video_edit_person_divison_video;2 38 ml_video_edit_oneclick_adaptis.pb;3 6 hdc_tb_cn_neg.tflite;3 281 +decoder_step_201217.pb;5 187 +ml_video_edit_art_transfer.onnx;3 3 +decoder.onnx;2;1,7,512:1,7 113 +decoder_step_201217_modified.pb;5 0.5 +encoder_0111_control_flow.pb;4;1:1,44:1:1 10 \ No newline at end of file diff --git a/mindspore/lite/test/run_benchmark_nets.sh b/mindspore/lite/test/run_benchmark_nets.sh index 2d318a2e42..4fb18f854e 100755 --- a/mindspore/lite/test/run_benchmark_nets.sh +++ b/mindspore/lite/test/run_benchmark_nets.sh @@ -167,69 +167,6 @@ function Run_Converter() { fi done < ${models_tflite_awaretraining_config} - # Copy fp16 ms models: - while read line; do - fp16_line_info=${line} - if [[ $fp16_line_info == \#* ]]; then - continue - fi - model_info=`echo ${fp16_line_info}|awk -F ' ' '{print $1}'` - model_name=${model_info%%;*} - echo 'cp '${ms_models_path}'/'${model_name}'.ms' ${ms_models_path}'/'${model_name}'.fp16.ms' - cp ${ms_models_path}/${model_name}.ms ${ms_models_path}/${model_name}.fp16.ms - if [ $? = 0 ]; then - converter_result='converter fp16 '${model_name}' pass';echo ${converter_result} >> ${run_converter_result_file} - else - converter_result='converter fp16 '${model_name}' failed';echo ${converter_result} >> ${run_converter_result_file};return 1 - fi - done < ${models_onnx_fp16_config} - - while read line; do - fp16_line_info=${line} - if [[ $fp16_line_info == \#* ]]; then - continue - fi - model_name=`echo ${fp16_line_info}|awk -F ' ' '{print $1}'` - echo 'cp '${ms_models_path}'/'${model_name}'.ms' ${ms_models_path}'/'${model_name}'.fp16.ms' - cp ${ms_models_path}/${model_name}.ms ${ms_models_path}/${model_name}.fp16.ms - if [ $? = 0 ]; then - converter_result='converter fp16 '${model_name}' pass';echo ${converter_result} >> ${run_converter_result_file} - else - converter_result='converter fp16 '${model_name}' failed';echo ${converter_result} >> ${run_converter_result_file};return 1 - fi - done < ${models_caffe_fp16_config} - - while read line; do - fp16_line_info=${line} - if [[ $fp16_line_info == \#* ]]; then - continue - fi - model_name=`echo ${fp16_line_info}|awk -F ' ' '{print $1}'` - echo 'cp '${ms_models_path}'/'${model_name}'.ms' ${ms_models_path}'/'${model_name}'.fp16.ms' - cp ${ms_models_path}/${model_name}.ms ${ms_models_path}/${model_name}.fp16.ms - if [ $? = 0 ]; then - converter_result='converter fp16 '${model_name}' pass';echo ${converter_result} >> ${run_converter_result_file} - else - converter_result='converter fp16 '${model_name}' failed';echo ${converter_result} >> ${run_converter_result_file};return 1 - fi - done < ${models_tflite_fp16_config} - - while read line; do - fp16_line_info=${line} - if [[ $fp16_line_info == \#* ]]; then - continue - fi - model_name=`echo ${fp16_line_info}|awk -F ' ' '{print $1}'` - input_num=`echo ${fp16_line_info}|awk -F ' ' '{print $2}'` - echo 'cp '${ms_models_path}'/'${model_name}'.ms' ${ms_models_path}'/'${model_name}'.fp16.ms' - cp ${ms_models_path}/${model_name}.ms ${ms_models_path}/${model_name}.fp16.ms - if [ $? = 0 ]; then - converter_result='converter fp16 '${model_name}' pass';echo ${converter_result} >> ${run_converter_result_file} - else - converter_result='converter fp16 '${model_name}' failed';echo ${converter_result} >> ${run_converter_result_file};return 1 - fi - done < ${models_tf_fp16_config} - # Convert tflite weightquant models: while read line; do weight_quant_line_info=${line} @@ -331,22 +268,6 @@ function Run_Converter() { fi done < ${models_with_multiple_inputs_config} - while read line; do - fp16_line_info=${line} - if [[ $fp16_line_info == \#* ]]; then - continue - fi - model_info=`echo ${fp16_line_info}|awk -F ' ' '{print $1}'` - model_name=${model_info%%;*} - echo 'cp '${ms_models_path}'/'${model_name}'.ms' ${ms_models_path}'/'${model_name}'.fp16.ms' - cp ${ms_models_path}/${model_name}.ms ${ms_models_path}/${model_name}.fp16.ms - if [ $? = 0 ]; then - converter_result='converter fp16 '${model_name}' pass';echo ${converter_result} >> ${run_converter_result_file} - else - converter_result='converter fp16 '${model_name}' failed';echo ${converter_result} >> ${run_converter_result_file};return 1 - fi - done < ${models_multiple_inputs_fp16_config} - # Convert models which does not need to be cared about the accuracy: while read line; do if [[ $line == \#* ]]; then @@ -387,6 +308,85 @@ function Run_Converter() { converter_result='converter '${model_type}' '${model_name}' failed';echo ${converter_result} >> ${run_converter_result_file};return 1 fi done < ${models_for_process_only_config} + + # Copy fp16 ms models: + while read line; do + fp16_line_info=${line} + if [[ $fp16_line_info == \#* ]]; then + continue + fi + model_info=`echo ${fp16_line_info}|awk -F ' ' '{print $1}'` + model_name=${model_info%%;*} + echo 'cp '${ms_models_path}'/'${model_name}'.ms' ${ms_models_path}'/'${model_name}'.fp16.ms' + cp ${ms_models_path}/${model_name}.ms ${ms_models_path}/${model_name}.fp16.ms + if [ $? = 0 ]; then + converter_result='converter fp16 '${model_name}' pass';echo ${converter_result} >> ${run_converter_result_file} + else + converter_result='converter fp16 '${model_name}' failed';echo ${converter_result} >> ${run_converter_result_file};return 1 + fi + done < ${models_onnx_fp16_config} + + while read line; do + fp16_line_info=${line} + if [[ $fp16_line_info == \#* ]]; then + continue + fi + model_name=`echo ${fp16_line_info}|awk -F ' ' '{print $1}'` + echo 'cp '${ms_models_path}'/'${model_name}'.ms' ${ms_models_path}'/'${model_name}'.fp16.ms' + cp ${ms_models_path}/${model_name}.ms ${ms_models_path}/${model_name}.fp16.ms + if [ $? = 0 ]; then + converter_result='converter fp16 '${model_name}' pass';echo ${converter_result} >> ${run_converter_result_file} + else + converter_result='converter fp16 '${model_name}' failed';echo ${converter_result} >> ${run_converter_result_file};return 1 + fi + done < ${models_caffe_fp16_config} + + while read line; do + fp16_line_info=${line} + if [[ $fp16_line_info == \#* ]]; then + continue + fi + model_name=`echo ${fp16_line_info}|awk -F ' ' '{print $1}'` + echo 'cp '${ms_models_path}'/'${model_name}'.ms' ${ms_models_path}'/'${model_name}'.fp16.ms' + cp ${ms_models_path}/${model_name}.ms ${ms_models_path}/${model_name}.fp16.ms + if [ $? = 0 ]; then + converter_result='converter fp16 '${model_name}' pass';echo ${converter_result} >> ${run_converter_result_file} + else + converter_result='converter fp16 '${model_name}' failed';echo ${converter_result} >> ${run_converter_result_file};return 1 + fi + done < ${models_tflite_fp16_config} + + while read line; do + fp16_line_info=${line} + if [[ $fp16_line_info == \#* ]]; then + continue + fi + model_info=`echo ${fp16_line_info}|awk -F ' ' '{print $1}'` + model_name=${model_info%%;*} + echo 'cp '${ms_models_path}'/'${model_name}'.ms' ${ms_models_path}'/'${model_name}'.fp16.ms' + cp ${ms_models_path}/${model_name}.ms ${ms_models_path}/${model_name}.fp16.ms + if [ $? = 0 ]; then + converter_result='converter fp16 '${model_name}' pass';echo ${converter_result} >> ${run_converter_result_file} + else + converter_result='converter fp16 '${model_name}' failed';echo ${converter_result} >> ${run_converter_result_file};return 1 + fi + done < ${models_tf_fp16_config} + + while read line; do + fp16_line_info=${line} + if [[ $fp16_line_info == \#* ]]; then + continue + fi + model_info=`echo ${fp16_line_info}|awk -F ' ' '{print $1}'` + model_name=${model_info%%;*} + echo 'cp '${ms_models_path}'/'${model_name}'.ms' ${ms_models_path}'/'${model_name}'.fp16.ms' + cp ${ms_models_path}/${model_name}.ms ${ms_models_path}/${model_name}.fp16.ms + if [ $? = 0 ]; then + converter_result='converter fp16 '${model_name}' pass';echo ${converter_result} >> ${run_converter_result_file} + else + converter_result='converter fp16 '${model_name}' failed';echo ${converter_result} >> ${run_converter_result_file};return 1 + fi + done < ${models_multiple_inputs_fp16_config} } # Run on x86 platform: @@ -1811,6 +1811,36 @@ function Run_arm64_fp16() { fi done < ${models_tflite_fp16_config} + # Run fp16 converted models: + while read line; do + fp16_line_info=${line} + if [[ $fp16_line_info == \#* ]]; then + continue + fi + model_info=`echo ${fp16_line_info}|awk -F ' ' '{print $1}'` + accuracy_limit=`echo ${fp16_line_info}|awk -F ' ' '{print $2}'` + model_name=${model_info%%;*} + length=${#model_name} + input_shapes=${model_info:length+1} + echo "---------------------------------------------------------" >> "${run_arm64_fp16_log_file}" + echo "fp16 run: ${model_name}, accuracy limit:${accuracy_limit}" >> "${run_arm64_fp16_log_file}" + + echo 'cd /data/local/tmp/benchmark_test' > adb_run_cmd.txt + echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/local/tmp/benchmark_test' >> adb_run_cmd.txt + if [[ $accuracy_limit == "-1" ]]; then + echo './benchmark --modelFile='${model_name}'.fp16.ms --inDataFile=/data/local/tmp/input_output/input/'${model_name}'.ms.bin --enableFp16=true --inputShapes='${input_shapes} >> adb_run_cmd.txt + else + echo './benchmark --modelFile='${model_name}'.fp16.ms --inDataFile=/data/local/tmp/input_output/input/'${model_name}'.ms.bin --benchmarkDataFile=/data/local/tmp/input_output/output/'${model_name}'.ms.out --enableFp16=true --accuracyThreshold='${accuracy_limit} ' --inputShapes='${input_shapes} >> adb_run_cmd.txt + fi + cat adb_run_cmd.txt >> "${run_arm64_fp16_log_file}" + adb -s ${device_id} shell < adb_run_cmd.txt >> "${run_arm64_fp16_log_file}" + if [ $? = 0 ]; then + run_result='arm64_fp16: '${model_name}' pass'; echo ${run_result} >> ${run_benchmark_result_file} + else + run_result='arm64_fp16: '${model_name}' failed'; echo ${run_result} >> ${run_benchmark_result_file}; return 1 + fi + done < ${models_tf_fp16_config} + # Run converted models which has multiple inputs in fp16 mode: while read line; do fp16_line_info=${line} @@ -1848,35 +1878,6 @@ function Run_arm64_fp16() { run_result='arm64_fp16: '${model_name}' failed'; echo ${run_result} >> ${run_benchmark_result_file}; return 1 fi done < ${models_multiple_inputs_fp16_config} - - # Run tf fp16 models - while read line; do - tf_line_info=${line} - if [[ $tf_line_info == \#* ]]; then - continue - fi - model_name=`echo ${tf_line_info}|awk -F ' ' '{print $1}'` - model_info=`echo ${tf_line_info}|awk -F ' ' '{print $2}'` - input_num=`echo ${model_info}|awk -F ';' '{print $1}'` - input_shapes=`echo ${model_info}|awk -F ';' '{print $2}'` - accuracy_limit=`echo ${model_info}|awk -F ';' '{print $3}'` - input_files='' - for i in $(seq 1 $input_num) - do - input_files=$input_files'/data/local/tmp/input_output/input/'$model_name'.ms_'$i'.bin,' - done - echo ${model_name} >> "${run_arm64_fp16_log_file}" - echo 'cd /data/local/tmp/benchmark_test' > adb_run_cmd.txt - echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/local/tmp/benchmark_test;./benchmark --inputShapes='${input_shapes}' --modelFile='${model_name}'.fp16.ms --inDataFile='${input_files}' --benchmarkDataFile=/data/local/tmp/input_output/output/'${model_name}'.ms.out --enableFp16=true --accuracyThreshold='${accuracy_limit} >> adb_run_cmd.txt - echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/data/local/tmp/benchmark_test;./benchmark --inputShapes='${input_shapes}' --modelFile='${model_name}'.fp16.ms --inDataFile='${input_files}' --benchmarkDataFile=/data/local/tmp/input_output/output/'${model_name}'.ms.out --enableFp16=true --accuracyThreshold='${accuracy_limit} >> adb_run_cmd.txt - cat adb_run_cmd.txt >> "${run_arm64_fp16_log_file}" - adb -s ${device_id} shell < adb_run_cmd.txt >> "${run_arm64_fp16_log_file}" - if [ $? = 0 ]; then - run_result='arm64_fp16: '${model_name}' pass'; echo ${run_result} >> ${run_benchmark_result_file} - else - run_result='arm64_fp16: '${model_name}' failed'; echo ${run_result} >> ${run_benchmark_result_file}; return 1 - fi - done < ${models_tf_fp16_config} } # Run on gpu platform: function Run_gpu() { @@ -2133,6 +2134,7 @@ models_onnx_config=${basepath}/models_onnx.cfg models_onnx_fp16_config=${basepath}/models_onnx_fp16.cfg models_caffe_fp16_config=${basepath}/models_caffe_fp16.cfg models_tflite_fp16_config=${basepath}/models_tflite_fp16.cfg +models_tf_fp16_config=${basepath}/models_tf_fp16.cfg models_multiple_inputs_fp16_config=${basepath}/models_with_multiple_inputs_fp16.cfg models_mindspore_config=${basepath}/models_mindspore.cfg models_mindspore_train_config=${basepath}/models_mindspore_train.cfg @@ -2146,7 +2148,6 @@ models_npu_config=${basepath}/models_npu.cfg models_compatibility_config=${basepath}/models_compatibility.cfg models_with_multiple_inputs_config=${basepath}/models_with_multiple_inputs.cfg models_for_process_only_config=${basepath}/models_for_process_only.cfg -models_tf_fp16_config=${basepath}/models_tf_fp16.cfg ms_models_path=${basepath}/ms_models