PaddlePaddle / FastDeploy

⚡️An Easy-to-use and Fast Deep Learning Model Deployment Toolkit for ☁️Cloud 📱Mobile and 📹Edge. Including Image, Video, Text and Audio 20+ main stream scenarios and 150+ SOTA models with end-to-end optimization, multi-platform and multi-framework support.
https://www.paddlepaddle.org.cn/fastdeploy
Apache License 2.0
2.9k stars 453 forks source link

用rknpu转换识别模型出错: onnx.onnx_cpp2py_export.checker.ValidationError: Field 'shape' of type is required but missing. #2320

Open JoeyZhu opened 9 months ago

JoeyZhu commented 9 months ago

环境

问题日志及出现问题的操作流程

按照这个文档操作的https://github.com/PaddlePaddle/FastDeploy/blob/develop/examples/vision/ocr/PP-OCR/rockchip/cpp/README.md。 使用上面文档里面链接下载的PP-OCRv3文字识别模型,可以顺利转onnx,转rknn,使用我自己训练过的识别模型可以转onnx,但转rknn就报错退出了: python ../export.py --config_path ppocrv3_rec.yaml --target_platform rk3588 {'mean': [[127.5, 127.5, 127.5]], 'std': [[127.5, 127.5, 127.5]], 'model_path': './ch_PP-OCRv3_rec_infer/ch_PP-OCRv3_rec_infer.onnx', 'outputs_nodes': None, 'do_quantization': False, 'dataset': None, 'output_folder': './ch_PP-OCRv3_rec_infer'} W __init__: rknn-toolkit2 version: 1.5.0+1fa95b5c E load_onnx: Catch exception when loading onnx model: /home/joey/samplecodes/2023/FastDeploy/examples/vision/ocr/PP-OCR/rockchip/rknpu2_tools/config/ch_PP-OCRv3_rec_infer/ch_PP-OCRv3_rec_infer.onnx! E load_onnx: Traceback (most recent call last): E load_onnx: File "rknn/api/rknn_base.py", line 1382, in rknn.api.rknn_base.RKNNBase.load_onnx E load_onnx: File "rknn/api/rknn_base.py", line 658, in rknn.api.rknn_base.RKNNBase._create_ir_and_inputs_meta E load_onnx: File "rknn/api/ir_graph.py", line 58, in rknn.api.ir_graph.IRGraph.__init__ E load_onnx: File "rknn/api/ir_graph.py", line 503, in rknn.api.ir_graph.IRGraph.rebuild E load_onnx: File "/home/joey/anaconda3/envs/rknn/lib/python3.6/site-packages/onnx/checker.py", line 106, in check_model E load_onnx: C.check_model(protobuf_string) E load_onnx: onnx.onnx_cpp2py_export.checker.ValidationError: Field 'shape' of type is required but missing. W If you can't handle this error, please try updating to the latest version of the toolkit2 and runtime from: https://eyun.baidu.com/s/3eTDMk6Y (Pwd: rknn) Path: RK_NPU_SDK / RK_NPU_SDK_1.X.0 / develop / If the error still exists in the latest version, please collect the corresponding error logs and the model, convert script, and input data that can reproduce the problem, and then submit an issue on: https://redmine.rock-chips.com (Please consult our sales or FAE for the redmine account) Traceback (most recent call last): File "../export.py", line 52, in <module> assert ret == 0, "Load model failed!" AssertionError: Load model failed!

训练代码是:PaddleOCR-release-2.6,训练命令是:

python3 -m paddle.distributed.launch --gpus '0'  tools/train.py -c configs/rec/PP-OCRv3/ch_PP-OCRv3_rec_distillation.yml -o Global.pretrained_model=./pretrain_models/ch_PP-OCRv3_rec_train/best_accuracy

导出pdmodel命令是:

python3 tools/export_model.py -c  configs/rec/PP-OCRv3/ch_PP-OCRv3_rec_distillation.yml -o Global.pretrained_model=./output/rec_ppocr_v3_distillation/best_accuracy  Global.save_inference_dir=./inference/ch_PP-OCRv3_rec_rubber/

训练配置文件: `Global: debug: false use_gpu: true epoch_num: 900 log_smooth_window: 20 print_batch_step: 10 save_model_dir: ./output/rec_ppocr_v3_distillation save_epoch_step: 90 eval_batch_step: [0, 2000] cal_metric_during_train: true pretrained_model: checkpoints: save_inference_dir: use_visualdl: false infer_img: doc/imgs_words/ch/word_1.jpg character_dict_path: ppocr/utils/ppocr_keys_v1.txt max_text_length: &max_text_length 40 infer_mode: false use_space_char: true distributed: true save_res_path: ./output/rec/predicts_ppocrv3_distillation.txt use_amp: False

scale_loss: 1024.0

use_dynamic_loss_scaling: True

Optimizer: name: Adam beta1: 0.9 beta2: 0.999 lr: name: Piecewise decay_epochs : [700]

values : [0.0005, 0.00005]

values: [0.00005, 0.00001]
warmup_epoch: 5

regularizer: name: L2 factor: 3.0e-05

Architecture: model_type: &model_type "rec" name: DistillationModel algorithm: Distillation Models: Teacher: pretrained: freeze_params: false return_all_feats: true model_type: *model_type algorithm: SVTR Transform: Backbone: name: MobileNetV1Enhance scale: 0.5 last_conv_stride: [1, 2] last_pool_type: avg Head: name: MultiHead head_list:

PostProcess: name: DistillationCTCLabelDecode model_name: ["Student", "Teacher"] key: head_out multi_head: True

Metric: name: DistillationMetric base_metric_name: RecMetric main_indicator: acc key: "Student" ignore_space: False

Train: dataset: name: SimpleDataSet data_dir: /dataset/redecode_txt_recognition/ ext_op_transform_idx: 1 label_file_list:

`

JoeyZhu commented 9 months ago

我比较了转出来的onnx是不一样的,应该pdmodel就有点不一样,是rknn的识别模型需要改架构吗?