PaddleOCR icon indicating copy to clipboard operation
PaddleOCR copied to clipboard

[SRN - PPOCR v4] Error when run predict inference

Open nhannguyen1003 opened this issue 9 months ago • 18 comments

请提供下述完整信息以便快速定位问题/Please provide the following information to quickly locate the problem

  • 系统环境/System Environment: macos Sonoma v14 - python3 ver 3.10.6
  • 版本号/Version:Paddle: PaddleOCR:PPOCR-V4 问题相关组件/Related components:SRN algorithm
  • 运行指令/Command Code:
python tools/infer/predict_rec.py  --image_dir="/Users/roy/Desktop/app with nhannguyen/LVTN/AI-modal/PaddleOCR/train/vietnamese/train/img_crop/im0001_2.jpg" \
                                   --use_gpu=False \
                                   --rec_algorithm="SRN" \
                                   --rec_model_dir="./inference/SRN"  \
                                   --rec_image_shape="1, 64, 256"  \
                                   --rec_char_dict_path="./ppocr/utils/dict/vi_dict.txt"

This is my config:

  debug: false
  use_gpu: false
  epoch_num: 1
  log_smooth_window: 20
  print_batch_step: 5
  save_model_dir: ./output/SRN
  save_epoch_step: 10
  eval_batch_step:
  - 30000
  - 40000
  cal_metric_during_train: false
  pretrained_model: /Users/roy/Desktop/app with nhannguyen/LVTN/AI-modal/PaddleOCR/det_r50_vd_sast_icdar15_v2.0_train/best_accuracy
  checkpoints: null
  save_inference_dir: ./inference/SRN
  use_visualdl: false
  infer_img: doc/imgs_words/en/word_1.png
  character_dict_path: ./ppocr/utils/dict/vi_dict.txt
  character_type: vi
  max_text_length: 25
  num_heads: 8
  infer_mode: false
  use_space_char: true
  save_res_path: ./output/SRN/predicts_srn.txt
  load_static_weights: true
  distributed: false
Optimizer:
  name: Adam
  beta1: 0.9
  beta2: 0.999
  clip_norm: 10.0
  lr:
    learning_rate: 0.0001
Architecture:
  model_type: rec
  algorithm: SRN
  in_channels: 1
  Transform: null
  Backbone:
    name: ResNetFPN
  Head:
    name: SRNHead
    max_text_length: 25
    num_heads: 8
    num_encoder_TUs: 2
    num_decoder_TUs: 4
    hidden_dims: 512
Loss:
  name: SRNLoss
PostProcess:
  name: SRNLabelDecode
Metric:
  name: RecMetric
  main_indicator: acc
Train:
  dataset:
    name: SimpleDataSet
    data_dir: ./train/vietnamese/train/img_crop
    label_file_list:
    - ./train/vietnamese/train/crop_label.txt
    ratio_list:
    - 1
    transforms:
    - DecodeImage:
        img_mode: BGR
        channel_first: false
    - SRNLabelEncode: null
    - SRNRecResizeImg:
        image_shape:
        - 1
        - 64
        - 256
    - KeepKeys:
        keep_keys:
        - image
        - label
        - length
        - encoder_word_pos
        - gsrm_word_pos
        - gsrm_slf_attn_bias1
        - gsrm_slf_attn_bias2
  loader:
    shuffle: false
    batch_size_per_card: 32
    drop_last: false
    num_workers: 8
Eval:
  dataset:
    name: SimpleDataSet
    data_dir: ./train/vietnamese/train/img_crop
    label_file_list:
    - ./train/vietnamese/train/crop_label.txt
    ratio_list:
    - 1
    transforms:
    - DecodeImage:
        img_mode: BGR
        channel_first: false
    - SRNLabelEncode: null
    - SRNRecResizeImg:
        image_shape:
        - 1
        - 64
        - 256
    - KeepKeys:
        keep_keys:
        - image
        - label
        - length
        - encoder_word_pos
        - gsrm_word_pos
        - gsrm_slf_attn_bias1
        - gsrm_slf_attn_bias2
  loader:
    shuffle: false
    drop_last: false
    batch_size_per_card: 32
    num_workers: 8
profiler_options: null
  • 完整报错/Complete Error Message:
Traceback (most recent call last):
  File "/Users/roy/Desktop/app with nhannguyen/LVTN/AI-modal/PaddleOCR/tools/infer/predict_rec.py", line 743, in <module>
    main(utility.parse_args())
  File "/Users/roy/Desktop/app with nhannguyen/LVTN/AI-modal/PaddleOCR/tools/infer/predict_rec.py", line 704, in main
    text_recognizer = TextRecognizer(args)
  File "/Users/roy/Desktop/app with nhannguyen/LVTN/AI-modal/PaddleOCR/tools/infer/predict_rec.py", line 147, in __init__
    ) = utility.create_predictor(args, "rec", logger)
  File "/Users/roy/Desktop/app with nhannguyen/LVTN/AI-modal/PaddleOCR/tools/infer/utility.py", line 296, in create_predictor
    predictor = inference.create_predictor(config)
ValueError: (InvalidArgument) The Input Variable(X) of (reshape2) Operator used to determine kernel data type is empty or not phi::DenseTensor or SelectedRows or LoDTensorArray.
  [Hint: Expected data_type != dafault_data_type, but received data_type:-1 == dafault_data_type:-1.] (at /Users/paddle/xly/workspace/77aceb8e-2a5b-4fe4-a675-547f3aad14a4/Paddle/paddle/fluid/framework/operator.cc:2932)
  [operator < reshape2 > error]

nhannguyen1003 avatar May 02 '24 14:05 nhannguyen1003

更新一下paddle版本试试

GreatV avatar May 09 '24 02:05 GreatV

更新一下paddle版本试试

UserWangZz avatar May 09 '24 12:05 UserWangZz

更新一下paddle版本试试

which version

nhannguyen1003 avatar May 09 '24 15:05 nhannguyen1003

@nhannguyen1003 maybe paddlepaddle2.5 or 2.6

GreatV avatar May 09 '24 15:05 GreatV

@nhannguyen1003 maybe paddlepaddle2.5 or 2.6

I've use paddle2.6.1 and paddleocr2.7.5 but it's still not work. When I turn on GPU it work but nothing happen. Can you share me about your paddle version?

nhannguyen1003 avatar May 09 '24 15:05 nhannguyen1003

hi @nhannguyen1003, I can reproduce this issue, which may be a bug.

  warnings.warn(
Traceback (most recent call last):
  File "/home/greatx/repos/PaddleOCR/tools/infer/predict_rec.py", line 743, in <module>
    main(utility.parse_args())
  File "/home/greatx/repos/PaddleOCR/tools/infer/predict_rec.py", line 704, in main
    text_recognizer = TextRecognizer(args)
  File "/home/greatx/repos/PaddleOCR/tools/infer/predict_rec.py", line 147, in __init__
    ) = utility.create_predictor(args, "rec", logger)
  File "/home/greatx/repos/PaddleOCR/tools/infer/utility.py", line 296, in create_predictor
    predictor = inference.create_predictor(config)
ValueError: (InvalidArgument) The Input Variable(X) of (reshape2) Operator used to determine kernel data type is empty or not phi::DenseTensor or SelectedRows or LoDTensorArray.
  [Hint: Expected data_type != dafault_data_type, but received data_type:-1 == dafault_data_type:-1.] (at ../paddle/fluid/framework/operator.cc:2924)
  [operator < reshape2 > error]

GreatV avatar May 10 '24 00:05 GreatV

the predict mode worked for me

python3 tools/infer_rec.py -c configs/rec/rec_r50_fpn_srn.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png

GreatV avatar May 10 '24 02:05 GreatV

所以是predic_rec脚本出现问题了吗?

the predict mode worked for me

python3 tools/infer_rec.py -c configs/rec/rec_r50_fpn_srn.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png

UserWangZz avatar May 10 '24 02:05 UserWangZz

所以是predic_rec脚本出现问题了吗?

估计和静态图推理有关

GreatV avatar May 10 '24 02:05 GreatV

所以是predic_rec脚本出现问题了吗?

估计和静态图推理有关

the predict mode worked for me

python3 tools/infer_rec.py -c configs/rec/rec_r50_fpn_srn.yml -o Global.pretrained_model={path/to/weights}/best_accuracy Global.infer_img=doc/imgs_words/en/word_1.png

Could you please to give me your configuration?

leapvn-nhannt avatar May 10 '24 09:05 leapvn-nhannt

@leapvn-nhannt just configs/rec/rec_r50_fpn_srn.yml, no change

GreatV avatar May 10 '24 10:05 GreatV

@leapvn-nhannt just configs/rec/rec_r50_fpn_srn.yml, no change

Could you mind to give me your environment: python: , paddleocr, paddlepaddle?

nhannguyen1003 avatar May 10 '24 13:05 nhannguyen1003

@nhannguyen1003 paddlepaddle 2.6.1, latest paddleocr in main branch, and python 3.10

GreatV avatar May 10 '24 13:05 GreatV

@nhannguyen1003 paddlepaddle 2.6.1, latest paddleocr in main branch, and python 3.10

I've checked and found that it's available when run infer_rec, but when exported to inference it isn't work.

nhannguyen1003 avatar May 12 '24 02:05 nhannguyen1003

hi @nhannguyen1003, this will take time to check in depth and I will look into it further.

GreatV avatar May 12 '24 02:05 GreatV

@nhannguyen1003 maybe paddlepaddle2.5 or 2.6

请问paddleocr 支持batch 推理吗?

bigmover avatar May 21 '24 09:05 bigmover

@nhannguyen1003 你的问题解决了么?可以告诉我吗

gioiace2001 avatar May 30 '24 03:05 gioiace2001

hi @nhannguyen1003, this will take time to check in depth and I will look into it further.

Did you solved this problem? Please tell me if problem is solved

ltkien0105 avatar Aug 10 '24 04:08 ltkien0105

@ltkien0105 not yet.

GreatV avatar Aug 30 '24 05:08 GreatV