| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  | #!/bin/bash
 | 
					
						
							|  |  |  | source ./test_tipc/common_func.sh | 
					
						
							|  |  |  | FILENAME=$1 | 
					
						
							|  |  |  | dataline=$(cat ${FILENAME}) | 
					
						
							|  |  |  | # parser params | 
					
						
							|  |  |  | IFS=$'\n' | 
					
						
							|  |  |  | lines=(${dataline}) | 
					
						
							|  |  |  | IFS=$'\n' | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  | paddlelite_library_source=$2 | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | inference_cmd=$(func_parser_value "${lines[1]}") | 
					
						
							|  |  |  | DEVICE=$(func_parser_value "${lines[2]}") | 
					
						
							|  |  |  | det_lite_model_list=$(func_parser_value "${lines[3]}") | 
					
						
							|  |  |  | rec_lite_model_list=$(func_parser_value "${lines[4]}") | 
					
						
							|  |  |  | cls_lite_model_list=$(func_parser_value "${lines[5]}") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  | if [[ $inference_cmd =~ "det" ]]; then | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  |     lite_model_list=${det_lite_model_list} | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  | elif [[ $inference_cmd =~ "rec" ]]; then | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  |     lite_model_list=(${rec_lite_model_list[*]} ${cls_lite_model_list[*]}) | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  | elif [[ $inference_cmd =~ "system" ]]; then | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  |     lite_model_list=(${det_lite_model_list[*]} ${rec_lite_model_list[*]} ${cls_lite_model_list[*]}) | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |     echo "inference_cmd is wrong, please check." | 
					
						
							|  |  |  |     exit 1 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  | if [ ${DEVICE} = "ARM_CPU" ]; then | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  |     valid_targets="arm" | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  |     paddlelite_library_url="https://github.com/PaddlePaddle/Paddle-Lite/releases/download/v2.10-rc/inference_lite_lib.android.armv8.gcc.c++_shared.with_extra.with_cv.tar.gz" | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  |     end_index="66" | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  |     compile_with_opencl="OFF" | 
					
						
							|  |  |  | elif [ ${DEVICE} = "ARM_GPU_OPENCL" ]; then | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  |     valid_targets="opencl" | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  |     paddlelite_library_url="https://github.com/PaddlePaddle/Paddle-Lite/releases/download/v2.10-rc/inference_lite_lib.armv8.clang.with_exception.with_extra.with_cv.opencl.tar.gz" | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  |     end_index="71" | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  |     compile_with_opencl="ON" | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  | else | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  |     echo "DEVICE only support ARM_CPU, ARM_GPU_OPENCL." | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  |     exit 2     | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  | # prepare paddlelite model | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  | pip install paddlelite==2.10-rc | 
					
						
							|  |  |  | current_dir=${PWD} | 
					
						
							|  |  |  | IFS="|" | 
					
						
							|  |  |  | model_path=./inference_models | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | for model in ${lite_model_list[*]}; do | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  |     if [[ $model =~ "PP-OCRv2" ]]; then | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  |         inference_model_url=https://paddleocr.bj.bcebos.com/PP-OCRv2/chinese/${model}.tar | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  |     elif [[ $model =~ "v2.0" ]]; then | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  |         inference_model_url=https://paddleocr.bj.bcebos.com/dygraph_v2.0/ch/${model}.tar | 
					
						
							|  |  |  |     else  | 
					
						
							|  |  |  |         echo "Model is wrong, please check." | 
					
						
							|  |  |  |         exit 3 | 
					
						
							|  |  |  |     fi | 
					
						
							|  |  |  |     inference_model=${inference_model_url##*/} | 
					
						
							|  |  |  |     wget -nc  -P ${model_path} ${inference_model_url} | 
					
						
							|  |  |  |     cd ${model_path} && tar -xf ${inference_model} && cd ../ | 
					
						
							|  |  |  |     model_dir=${model_path}/${inference_model%.*} | 
					
						
							|  |  |  |     model_file=${model_dir}/inference.pdmodel | 
					
						
							|  |  |  |     param_file=${model_dir}/inference.pdiparams | 
					
						
							|  |  |  |     paddle_lite_opt --model_dir=${model_dir} --model_file=${model_file} --param_file=${param_file} --valid_targets=${valid_targets} --optimize_out=${model_dir}_opt | 
					
						
							|  |  |  | done | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # prepare test data | 
					
						
							|  |  |  | data_url=https://paddleocr.bj.bcebos.com/dygraph_v2.0/test/icdar2015_lite.tar | 
					
						
							|  |  |  | data_file=${data_url##*/} | 
					
						
							|  |  |  | wget -nc  -P ./test_data ${data_url} | 
					
						
							|  |  |  | cd ./test_data && tar -xf ${data_file} && rm ${data_file} && cd ../ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  | # prepare paddlelite predict library | 
					
						
							|  |  |  | if [[ ${paddlelite_library_source} = "download" ]]; then | 
					
						
							|  |  |  |     paddlelite_library_zipfile=$(echo $paddlelite_library_url | awk -F "/" '{print $NF}') | 
					
						
							|  |  |  |     paddlelite_library_file=${paddlelite_library_zipfile:0:${end_index}} | 
					
						
							|  |  |  |     wget ${paddlelite_library_url} && tar -xf ${paddlelite_library_zipfile} | 
					
						
							|  |  |  |     cd ${paddlelite_library_zipfile} | 
					
						
							|  |  |  | elif [[ ${paddlelite_library_source} = "compile" ]]; then | 
					
						
							|  |  |  |     git clone -b release/v2.10 https://github.com/PaddlePaddle/Paddle-Lite.git | 
					
						
							|  |  |  |     cd Paddle-Lite | 
					
						
							|  |  |  |     ./lite/tools/build_android.sh  --arch=armv8  --with_cv=ON --with_extra=ON --toolchain=clang --with_opencl=${compile_with_opencl} | 
					
						
							|  |  |  |     cd ../ | 
					
						
							|  |  |  |     cp -r Paddle-Lite/build.lite.android.armv8.clang/inference_lite_lib.android.armv8/ . | 
					
						
							|  |  |  |     paddlelite_library_file=inference_lite_lib.android.armv8 | 
					
						
							|  |  |  | else | 
					
						
							|  |  |  |     echo "paddlelite_library_source only support 'download' and 'compile'" | 
					
						
							|  |  |  |     exit 3 | 
					
						
							|  |  |  | fi | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | # organize the required files   | 
					
						
							|  |  |  | mkdir -p  ${paddlelite_library_file}/demo/cxx/ocr/test_lite | 
					
						
							|  |  |  | cp -r ${model_path}/*_opt.nb test_data ${paddlelite_library_file}/demo/cxx/ocr/test_lite | 
					
						
							|  |  |  | cp ppocr/utils/ppocr_keys_v1.txt deploy/lite/config.txt ${paddlelite_library_file}/demo/cxx/ocr/test_lite | 
					
						
							|  |  |  | cp -r ./deploy/lite/* ${paddlelite_library_file}/demo/cxx/ocr/ | 
					
						
							|  |  |  | cp ${paddlelite_library_file}/cxx/lib/libpaddle_light_api_shared.so ${paddlelite_library_file}/demo/cxx/ocr/test_lite | 
					
						
							|  |  |  | cp ${FILENAME} test_tipc/test_lite_arm_cpp.sh test_tipc/common_func.sh ${paddlelite_library_file}/demo/cxx/ocr/test_lite | 
					
						
							|  |  |  | cd ${paddlelite_library_file}/demo/cxx/ocr/ | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  | git clone https://github.com/cuicheng01/AutoLog.git | 
					
						
							| 
									
										
										
										
											2021-11-18 02:48:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  | # compile and do some postprocess | 
					
						
							| 
									
										
										
										
											2021-11-18 02:34:56 +00:00
										 |  |  | make -j | 
					
						
							|  |  |  | sleep 1 | 
					
						
							|  |  |  | make -j | 
					
						
							|  |  |  | cp ocr_db_crnn test_lite && cp test_lite/libpaddle_light_api_shared.so test_lite/libc++_shared.so | 
					
						
							|  |  |  | tar -cf test_lite.tar ./test_lite && cp test_lite.tar ${current_dir} && cd ${current_dir} | 
					
						
							| 
									
										
										
										
											2021-11-25 02:50:16 +00:00
										 |  |  | rm -rf ${paddlelite_library_file}* && rm -rf ${model_path} |