PaddlePaddle / PaddleOCR

Awesome multilingual OCR toolkits based on PaddlePaddle (practical ultra lightweight OCR system, support 80+ languages recognition, provide data annotation and synthesis tools, support training and deployment among server, mobile, embedded and IoT devices)
https://paddlepaddle.github.io/PaddleOCR/
Apache License 2.0
42.81k stars 7.69k forks source link

运行predict_kie_token_ser_re官网示例报错 #11196

Closed zhh8689 closed 3 months ago

zhh8689 commented 10 months ago

系统环境/System Environment:苹果 m2

版本号/Version:Paddle: 2.5.2 PaddleOCR: 2.7.0.3 paddlenlp: 2.6.1

运行指令/Command Code:

python3 predict_system.py \ --kie_algorithm=LayoutXLM \ --re_model_dir=./inference/re_vi_layoutxlm_xfund_infer \ --ser_model_dir=./inference/ser_vi_layoutxlm_xfund_infer \ --image_dir=./docs/kie/input/zh_val_42.jpg \ --ser_dict_path=../ppocr/utils/dict/kie_dict/xfund_class_list.txt \ --vis_font_path=../doc/fonts/simfang.ttf \ --ocr_order_method="tb-yx" \ --mode=kie

完整报错/Complete Error Message: python3 predict_system.py \ --kie_algorithm=LayoutXLM \ --re_model_dir=./inference/re_vi_layoutxlm_xfund_infer \ --ser_model_dir=./inference/ser_vi_layoutxlm_xfund_infer \ --image_dir=./docs/kie/input/zh_val_42.jpg \ --ser_dict_path=../ppocr/utils/dict/kie_dict/xfund_class_list.txt \ --vis_font_path=../doc/fonts/simfang.ttf \ --ocr_order_method="tb-yx" \ --mode=kie [2023-11-05 11:23:31,776] [ INFO] - Already cached /Users/zhaohua/.paddlenlp/models/layoutxlm-base-uncased/sentencepiece.bpe.model [2023-11-05 11:23:32,012] [ INFO] - tokenizer config file saved in /Users/zhaohua/.paddlenlp/models/layoutxlm-base-uncased/tokenizer_config.json [2023-11-05 11:23:32,013] [ INFO] - Special tokens file saved in /Users/zhaohua/.paddlenlp/models/layoutxlm-base-uncased/special_tokens_map.json E1105 11:23:32.198127 4179861632 analysis_config.cc:121] Please use PaddlePaddle with GPU version. E1105 11:23:33.674060 4179861632 analysis_config.cc:121] Please use PaddlePaddle with GPU version. [2023/11/05 11:23:35] ppocr INFO: [0/1] ./docs/kie/input/zh_val_42.jpg Corrupt JPEG data: premature end of data segment Traceback (most recent call last): File "/Users/zhaohua/Downloads/PaddleOCR-release-2.6/ppstructure/predict_system.py", line 328, in main(args) File "/Users/zhaohua/Downloads/PaddleOCR-release-2.6/ppstructure/predict_system.py", line 266, in main res, time_dict = structure_sys(img, img_idx=index) File "/Users/zhaohua/Downloads/PaddleOCR-release-2.6/ppstructure/predict_system.py", line 193, in call re_res, elapse = self.kie_predictor(img) File "/Users/zhaohua/Downloads/PaddleOCR-release-2.6/ppstructure/kie/predict_kie_token_ser_re.py", line 64, in call self.predictor.run() ValueError: In user code:

File "tools/export_model.py", line 258, in <module>
  main()
File "tools/export_model.py", line 254, in main
  model, arch_config, save_path, logger, input_shape=input_shape)
File "tools/export_model.py", line 174, in export_single_model
  paddle.jit.save(model, save_path)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/jit.py", line 631, in wrapper
  func(layer, path, input_spec, **configs)
File "<decorator-gen-106>", line 2, in save

File "/usr/local/lib/python3.7/site-packages/paddle/fluid/wrapped_decorator.py", line 25, in __impl__
  return wrapped_func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/base.py", line 51, in __impl__
  return func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/jit.py", line 861, in save
  inner_input_spec, with_hook=with_hook)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 528, in concrete_program_specify_input_spec
  *desired_input_spec, with_hook=with_hook)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 436, in get_concrete_program
  concrete_program, partial_program_layer = self._program_cache[cache_key]
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 801, in __getitem__
  self._caches[item_id] = self._build_once(item)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 790, in _build_once
  **cache_key.kwargs)
File "<decorator-gen-104>", line 2, in from_func_spec

File "/usr/local/lib/python3.7/site-packages/paddle/fluid/wrapped_decorator.py", line 25, in __impl__
  return wrapped_func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/base.py", line 51, in __impl__
  return func(*args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/program_translator.py", line 733, in from_func_spec
  outputs = static_func(*inputs)
File "/tmp/tmp1jzgs091.py", line 28, in forward
  false_fn_1, (x,), (x,), (x,))
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/convert_operators.py", line 211, in convert_ifelse
  out = _run_py_ifelse(pred, true_fn, false_fn, true_args, false_args)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/convert_operators.py", line 257, in _run_py_ifelse
  return true_fn(*true_args) if pred else false_fn(*false_args)
File "/ssd1/zhoujun20/tipc/PaddleOCR/ppocr/modeling/architectures/base_model.py", line 86, in forward
  x = self.backbone(x)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 930, in __call__
  return self._dygraph_call_func(*inputs, **kwargs)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 915, in _dygraph_call_func
  outputs = self.forward(*inputs, **kwargs)
File "/ssd1/zhoujun20/tipc/PaddleOCR/ppocr/modeling/backbones/vqa_layoutlm.py", line 237, in forward
  relations=relations)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 930, in __call__
  return self._dygraph_call_func(*inputs, **kwargs)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 915, in _dygraph_call_func
  outputs = self.forward(*inputs, **kwargs)
File "/usr/local/lib/python3.7/site-packages/paddlenlp/transformers/layoutxlm/modeling.py", line 1542, in forward
  relations)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 930, in __call__
  return self._dygraph_call_func(*inputs, **kwargs)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/layers.py", line 915, in _dygraph_call_func
  outputs = self.forward(*inputs, **kwargs)
File "/usr/local/lib/python3.7/site-packages/paddlenlp/transformers/layoutxlm/modeling.py", line 1408, in forward
  relations, entities = self.build_relation(relations, entities)
File "/tmp/tmpt8u0m8_d.py", line 106, in build_relation
  for_loop_body_2, [entities, new_relations, relations, b, batch_size])
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/convert_operators.py", line 43, in convert_while_loop
  loop_vars = _run_paddle_while_loop(cond, body, loop_vars)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/dygraph/dygraph_to_static/convert_operators.py", line 53, in _run_paddle_while_loop
  loop_vars = control_flow.while_loop(cond, body, loop_vars)
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/layers/control_flow.py", line 1257, in while_loop
  output_vars = body(*loop_vars)
File "/tmp/tmpt8u0m8_d.py", line 30, in for_loop_body_2
  paddle.jit.dy2static.convert_ifelse(entities[b, 0, 0] <= 2,
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/layers/math_op_patch.py", line 347, in __impl__
  attrs={'axis': axis})
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/framework.py", line 3621, in append_op
  attrs=kwargs.get("attrs", None))
File "/usr/local/lib/python3.7/site-packages/paddle/fluid/framework.py", line 2635, in __init__
  for frame in traceback.extract_stack():

InvalidArgumentError: The type of data we are trying to retrieve (int64) does not match the type of data (float32) currently contained in the container.
  [Hint: Expected dtype() == phi::CppTypeToDataType<T>::Type(), but received dtype():10 != phi::CppTypeToDataType<T>::Type():9.] (at /Users/paddle/xly/workspace/f4429c34-48ba-44c2-9571-abaff039446b/Paddle/paddle/phi/core/dense_tensor.cc:166)
  [operator < less_equal > error]
zzgHiker commented 10 months ago

降低paddlenlp的版本试试 之前使用paddlenlp==2.6.1也是报错,后来降低到2.5.2就正常了

zhh8689 commented 10 months ago

降低paddlenlp的版本试试 之前使用paddlenlp==2.6.1也是报错,后来降低到2.5.2就正常了

直接使用nlp是没有问题的,目前问题出在没办法使用re。但是使用taskflow,并且开启版面分析是没有问题的。看了下里面的代码,也是调用的ppstructure。有点摸不到头脑了