PaddleOCR 训练layoutxml re任务报错,ValueError: too many values to unpack (expected 3)

iqih9akk  于 2023-02-04  发布在  其他
关注(0)|答案(3)|浏览(318)

训练layoutxml re模型时报异常,训练ser模型时无此问题

  • 分别用自己的数据集和XFUND数据集进行了测试,都是同样的问题

  • 按照 issue4975cal_metric_during_train 设置为False无果

  • 系统环境/System Environment:CentOS7

  • 版本号/Version:Paddle:2.3.1.post112 PaddleOCR:2.6 PaddleNLP: 2.4.2 问题相关组件/Related components:/home/hr/anaconda3/lib/python3.9/site-packages/paddlenlp/transformers/layoutxlm/modeling.py

  • 运行指令/Command Code:python tools/train.py -c configs/hr/eop/re_vi_layoutxlm_zh.yml

  • 完整报错/Complete Error Message:

Traceback (most recent call last):
  File "/home/hr/projects/PaddleOCR/tools/train.py", line 208, in <module>
    main(config, device, logger, vdl_writer)
  File "/home/hr/projects/PaddleOCR/tools/train.py", line 180, in main
    program.train(config, train_dataloader, valid_dataloader, device, model,
  File "/home/hr/projects/PaddleOCR/tools/program.py", line 290, in train
    preds = model(batch)
  File "/home/hr/anaconda3/lib/python3.9/site-packages/paddle/fluid/dygraph/layers.py", line 930, in __call__
    return self._dygraph_call_func(*inputs, **kwargs)
  File "/home/hr/anaconda3/lib/python3.9/site-packages/paddle/fluid/dygraph/layers.py", line 915, in _dygraph_call_func
    outputs = self.forward(*inputs, **kwargs)
  File "/home/hr/projects/PaddleOCR/ppocr/modeling/architectures/base_model.py", line 86, in forward
    x = self.backbone(x)
  File "/home/hr/anaconda3/lib/python3.9/site-packages/paddle/fluid/dygraph/layers.py", line 930, in __call__
    return self._dygraph_call_func(*inputs, **kwargs)
  File "/home/hr/anaconda3/lib/python3.9/site-packages/paddle/fluid/dygraph/layers.py", line 915, in _dygraph_call_func
    outputs = self.forward(*inputs, **kwargs)
  File "/home/hr/projects/PaddleOCR/ppocr/modeling/backbones/vqa_layoutlm.py", line 227, in forward
    x = self.model(
  File "/home/hr/anaconda3/lib/python3.9/site-packages/paddle/fluid/dygraph/layers.py", line 930, in __call__
    return self._dygraph_call_func(*inputs, **kwargs)
  File "/home/hr/anaconda3/lib/python3.9/site-packages/paddle/fluid/dygraph/layers.py", line 915, in _dygraph_call_func
    outputs = self.forward(*inputs, **kwargs)
  File "/home/hr/anaconda3/lib/python3.9/site-packages/paddlenlp/transformers/layoutxlm/modeling.py", line 1558, in forward
    loss, pred_relations = self.extractor(sequence_output, entities,
  File "/home/hr/anaconda3/lib/python3.9/site-packages/paddle/fluid/dygraph/layers.py", line 930, in __call__
    return self._dygraph_call_func(*inputs, **kwargs)
  File "/home/hr/anaconda3/lib/python3.9/site-packages/paddle/fluid/dygraph/layers.py", line 915, in _dygraph_call_func
    outputs = self.forward(*inputs, **kwargs)
  File "/home/hr/anaconda3/lib/python3.9/site-packages/paddlenlp/transformers/layoutxlm/modeling.py", line 1424, in forward
    batch_size, max_length, _ = paddle.shape(entities)
ValueError: too many values to unpack (expected 3)

完整的配置文件信息

Global:
  use_gpu: True
  epoch_num: &epoch_num 130
  log_smooth_window: 10
  print_batch_step: 10
  save_model_dir: /home/hr/projects/ppocr/PaddleOCR/output/eop/re_vi_layoutxlm_zh
  save_epoch_step: 130
  # evaluation is run every 10 iterations after the 0th iteration
  eval_batch_step: 100
  cal_metric_during_train: False
  save_inference_dir:
  use_visualdl: False
  seed: 2022
  infer_img: 
  save_res_path: /home/hr/projects/ppocr/PaddleOCR/output/eop/re
  kie_rec_model_dir: 
  kie_det_model_dir:

Architecture:
  model_type: kie
  algorithm: &algorithm "LayoutXLM"
  Transform:
  Backbone:
    name: LayoutXLMForRe
    pretrained: True
    mode: vi
    checkpoints:

Loss:
  name: LossFromOutput
  key: loss
  reduction: mean

Optimizer:
  name: AdamW
  beta1: 0.9
  beta2: 0.999
  clip_norm: 10
  lr:
    learning_rate: 0.00005
    warmup_epoch: 10
  regularizer:
    name: L2
    factor: 0.00000
    
PostProcess:
  name: VQAReTokenLayoutLMPostProcess

Metric:
  name: VQAReTokenMetric
  main_indicator: hmean

Train:
  dataset:
    name: SimpleDataSet
    data_dir: data
    label_file_list: 
      - data/EOP/label.txt
    ratio_list: [ 1.0 ]
    transforms:
      - DecodeImage: # load image
          img_mode: RGB
          channel_first: False
      - VQATokenLabelEncode: # Class handling label
          contains_re: True
          algorithm: *algorithm
          class_path: &class_path /home/hr/projects/PaddleOCR/data/EOP/class_list.txt
          use_textline_bbox_info: &use_textline_bbox_info True
          order_method: &order_method "tb-yx"
      - VQATokenPad:
          max_seq_len: &max_seq_len 512
          return_attention_mask: True
      - VQAReTokenRelation:
      - VQAReTokenChunk:
          max_seq_len: *max_seq_len
      - Resize:
          size: [224,224]
      - NormalizeImage:
          scale: 1
          mean: [ 123.675, 116.28, 103.53 ]
          std: [ 58.395, 57.12, 57.375 ]
          order: 'hwc'
      - ToCHWImage:
      - KeepKeys:
          keep_keys: [ 'input_ids', 'bbox','attention_mask', 'token_type_ids', 'image', 'entities', 'relations'] # dataloader will return list in this order
  loader:
    shuffle: True
    drop_last: False
    batch_size_per_card: 4
    num_workers: 4
    collate_fn: ListCollator

Eval:
  dataset:
    name: SimpleDataSet
    data_dir: data
    label_file_list:
      - data/EOP/label.txt
    transforms:
      - DecodeImage: # load image
          img_mode: RGB
          channel_first: False
      - VQATokenLabelEncode: # Class handling label
          contains_re: True
          algorithm: *algorithm
          class_path: *class_path
          use_textline_bbox_info: *use_textline_bbox_info
          order_method: *order_method
      - VQATokenPad:
          max_seq_len: *max_seq_len
          return_attention_mask: True
      - VQAReTokenRelation:
      - VQAReTokenChunk:
          max_seq_len: *max_seq_len
      - Resize:
          size: [224,224]
      - NormalizeImage:
          scale: 1
          mean: [ 123.675, 116.28, 103.53 ]
          std: [ 58.395, 57.12, 57.375 ]
          order: 'hwc'
      - ToCHWImage:
      - KeepKeys:
          keep_keys: [ 'input_ids', 'bbox', 'attention_mask', 'token_type_ids', 'image', 'entities', 'relations'] # dataloader will return list in this order
  loader:
    shuffle: False
    drop_last: False
    batch_size_per_card: 8
    num_workers: 8
    collate_fn: ListCollator
zysjyyx4

zysjyyx41#

我尝试打印了 entities 的shape,结果发现是纬度为4,而问题代码 batch_size, max_length, _ = paddle.shape(entities) 是用三个变量来接收参数的,因此报错,请问怎么解决?

print(paddle.shape(entities)) (在vqa_layoutlm.py中打印了一下信息)

Tensor(shape=[4], dtype=int32, place=Place(cpu), stop_gradient=True,
       [4  , 3  , 224, 224])
l7mqbcuq

l7mqbcuq2#

@Evezerest 大佬可以帮忙看一下这个吗,我也遇到了一模一样 PaddleNLP是2.4.5版本都升级到最新了
ValueError: too many values to unpack (expected 3)

brqmpdu1

brqmpdu13#

一样的问题,请问如何解决,PaddleNLP 2.4.9

相关问题