PaddleOCR icon indicating copy to clipboard operation
PaddleOCR copied to clipboard

基于PaddleInference的预测 SER + RE模型串联报错 - Hint: Expected dtype() == paddle::experimental::CppTypeToDataType<T>::Type(), but received dtype():5 != paddle::experimental::CppTypeToDataType<T>::Type():7.] (at C:\home\workspace\Paddle_release\paddle\phi\core\dense_tensor.cc:137) [operator < less_equal > error

Open gg22mm opened this issue 2 years ago • 7 comments

SER + RE模型串联 - 下载 PaddleOCR-release-2.6 版本才支持

cd ppstructure python kie/predict_kie_token_ser_re.py --kie_algorithm=LayoutXLM --re_model_dir=../inference/re_vi_layoutxlm_xfund_infer --ser_model_dir=../inference/ser_vi_layoutxlm_xfund_infer --use_visual_backbone=False --image_dir=./docs/kie/input/zh_val_42.jpg --ser_dict_path=../train_data/XFUND/class_list_xfun.txt --vis_font_path=../doc/fonts/simfang.ttf --ocr_order_method="tb-yx" --use_gpu=false

图片 图片

(paddle2.3) E:\wll\phpsys\WWW\start\l__dzkj_test\test\resnet\paddle\PaddleOCR26\ppstructure>python kie/predict_kie_token_ser_re.py --kie_algorithm=LayoutXLM --re_model_dir=../inference/re_vi_layoutxlm_xfund_infer --ser_model_dir=../inference/ser_vi_layoutxlm_xfund_infer --use_visual_backbone=False --image_dir=./docs/kie/input/zh_val_42.jpg --ser_dict_path=../train_data/XFUND/class_list_xfun.txt --vis_font_path=../doc/fonts/simfang.ttf --ocr_order_method="tb-yx" --use_gpu=false [2022-11-02 14:47:28,016] [ INFO] - Already cached C:\Users\Administrator.paddlenlp\models\layoutxlm-base-uncased\sentencepiece.bpe.model [2022-11-02 14:47:28,726] [ INFO] - tokenizer config file saved in C:\Users\Administrator.paddlenlp\models\layoutxlm-base-uncased\tokenizer_config.json [2022-11-02 14:47:28,728] [ INFO] - Special tokens file saved in C:\Users\Administrator.paddlenlp\models\layoutxlm-base-uncased\special_tokens_map.json Corrupt JPEG data: premature end of data segment Traceback (most recent call last): File "kie/predict_kie_token_ser_re.py", line 135, in main(parse_args()) File "kie/predict_kie_token_ser_re.py", line 101, in main re_res, elapse = ser_re_predictor(img) File "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 does not match the type of data currently contained in the container.
  [Hint: Expected dtype() == paddle::experimental::CppTypeToDataType<T>::Type(), but received dtype():5 != paddle::experimental::CppTypeToDataType<T>::Type():7.] (at C:\home\workspace\Paddle_release\paddle\phi\core\dense_tensor.cc:137)
  [operator < less_equal > error]

gg22mm avatar Nov 02 '22 06:11 gg22mm

我也是相同的错误

feilu886 avatar Nov 02 '22 07:11 feilu886

我也是,明明环境是3.8,为啥python3.7会报错

BaiShiqing avatar Nov 03 '22 03:11 BaiShiqing

执行以下代码就好了 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

wanggoudanscd avatar Nov 03 '22 09:11 wanggoudanscd

执行以下代码就好了 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

还是不行,跟楼主相同的问题: InvalidArgumentError: The type of data we are trying to retrieve does not match the type of data currently contained in the container. [Hint: Expected dtype() == paddle::experimental::CppTypeToDataType<T>::Type(), but received dtype():12 != paddle::experimental::CppTypeToDataType<T>::Type():7 .] (at ..\paddle\phi\core\dense_tensor.cc:137) [operator < less_equal > error]

BaiShiqing avatar Nov 03 '22 10:11 BaiShiqing

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

不行呀,一样的。 检查一下代码吧。。 那么多人不行呢 回到:cd ppstructure 下载:inference 运行:python ./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 --use_gpu=false

gg22mm avatar Nov 04 '22 01:11 gg22mm

image 我的系统下没有“/usr/local/lib/python3.7”这个路径,说明paddle打包的时候引用了打包时的绝对地址 image 现在就是不知道哪里引的tools这个包

jhj033 avatar Nov 10 '22 12:11 jhj033

I have the exactly same problem when running paddleocr with type=structure. Errors will go to '/Users/zhoujun20/....'. If --use_gpu=false, then everything runs good. zhoujun20 is one developer?

sunwei317 avatar Nov 11 '22 02:11 sunwei317

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

不行呀,一样的。 检查一下代码吧。。 那么多人不行呢 回到:cd ppstructure 下载:inference 运行:python ./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 --use_gpu=false

这问题还没解决吗?我的也不行

DYF-AI avatar Dec 12 '22 14:12 DYF-AI

我遇到了相同的问题,后来改用这个文档里的命令可以正常运行

cd ppstructure
python3 kie/predict_kie_token_ser_re.py \
  --kie_algorithm=LayoutXLM \
  --re_model_dir=../inference/re_vi_layoutxlm_xfund_infer \
  --ser_model_dir=../inference/ser_vi_layoutxlm_xfund_infer \
  --use_visual_backbone=False \
  --image_dir=./docs/kie/input/zh_val_42.jpg \
  --ser_dict_path=../train_data/XFUND/class_list_xfun.txt \
  --vis_font_path=../doc/fonts/simfang.ttf \
  --ocr_order_method="tb-yx"

qinyuenlp avatar Dec 20 '22 03:12 qinyuenlp

我遇到了相同的问题,后来改用这个文档里的命令可以正常运行

cd ppstructure
python3 kie/predict_kie_token_ser_re.py \
  --kie_algorithm=LayoutXLM \
  --re_model_dir=../inference/re_vi_layoutxlm_xfund_infer \
  --ser_model_dir=../inference/ser_vi_layoutxlm_xfund_infer \
  --use_visual_backbone=False \
  --image_dir=./docs/kie/input/zh_val_42.jpg \
  --ser_dict_path=../train_data/XFUND/class_list_xfun.txt \
  --vis_font_path=../doc/fonts/simfang.ttf \
  --ocr_order_method="tb-yx"

我用这个好了,但是ser的范围变小了

Peno-zzp avatar Dec 29 '22 07:12 Peno-zzp

为啥要加这个--use_visual_backbone=False 好坑

LeoRainly avatar Jul 14 '23 06:07 LeoRainly