PaddleOCR icon indicating copy to clipboard operation
PaddleOCR copied to clipboard

compression of paddleOCR KIE model using PaddleSlim

Open pxike opened this issue 10 months ago • 1 comments

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

  • 系统环境/System Environment:Ubuntu 22.04
  • 版本号/Version:Paddle:2.5.2 PaddleOCR:2.7.0.3
  • 问题相关组件/Related components: PaddleSlim
  • 运行指令/Command Code: python PaddleOCR/deploy/slim/quantization/quant.py -c Models\cin_front\test-dml\output-mdl\config.yml -o Global.pretrained_model='./cin_front/test-dml/output/inference' Global.save_model_dir=./output/
  • 完整报错/Complete Error Message:
ut/
[2024/04/19 14:50:52] ppocr INFO: Architecture : 
[2024/04/19 14:50:52] ppocr INFO:     Models : 
[2024/04/19 14:50:52] ppocr INFO:         Student : 
[2024/04/19 14:50:52] ppocr INFO:             Backbone : 
[2024/04/19 14:50:52] ppocr INFO:                 checkpoints : None
[2024/04/19 14:50:52] ppocr INFO:                 mode : vi
[2024/04/19 14:50:52] ppocr INFO:                 name : LayoutXLMForSer
[2024/04/19 14:50:52] ppocr INFO:                 num_classes : 15
[2024/04/19 14:50:52] ppocr INFO:                 pretrained : True
[2024/04/19 14:50:52] ppocr INFO:             Transform : None
[2024/04/19 14:50:52] ppocr INFO:             algorithm : LayoutXLM
[2024/04/19 14:50:52] ppocr INFO:             freeze_params : False
[2024/04/19 14:50:52] ppocr INFO:             model_type : kie
[2024/04/19 14:50:52] ppocr INFO:             pretrained : None
[2024/04/19 14:50:52] ppocr INFO:             return_all_feats : True
[2024/04/19 14:50:52] ppocr INFO:         Teacher : 
[2024/04/19 14:50:52] ppocr INFO:             Backbone : 
[2024/04/19 14:50:52] ppocr INFO:                 checkpoints : None
[2024/04/19 14:50:52] ppocr INFO:                 mode : vi
[2024/04/19 14:50:52] ppocr INFO:                 name : LayoutXLMForSer
[2024/04/19 14:50:52] ppocr INFO:                 num_classes : 15
[2024/04/19 14:50:52] ppocr INFO:                 pretrained : True
[2024/04/19 14:50:52] ppocr INFO:             Transform : None
[2024/04/19 14:50:52] ppocr INFO:             algorithm : LayoutXLM
[2024/04/19 14:50:52] ppocr INFO:             freeze_params : False
[2024/04/19 14:50:52] ppocr INFO:             model_type : kie
[2024/04/19 14:50:52] ppocr INFO:             pretrained : None
[2024/04/19 14:50:52] ppocr INFO:             return_all_feats : True
[2024/04/19 14:50:52] ppocr INFO:     algorithm : Distillation
[2024/04/19 14:50:52] ppocr INFO:     model_type : kie
[2024/04/19 14:50:52] ppocr INFO:     name : DistillationModel
[2024/04/19 14:50:52] ppocr INFO: Eval : 
[2024/04/19 14:50:52] ppocr INFO:     dataset : 
[2024/04/19 14:50:52] ppocr INFO:         data_dir : /opt/waf-ocr/kie_train_data/cin_front/v11/val
[2024/04/19 14:50:52] ppocr INFO:         label_file_list : ['/opt/waf-ocr/kie_train_data/cin_front/v11/val.json']
[2024/04/19 14:50:52] ppocr INFO:         name : SimpleDataSet
[2024/04/19 14:50:52] ppocr INFO:         transforms : 
[2024/04/19 14:50:52] ppocr INFO:             DecodeImage : 
[2024/04/19 14:50:52] ppocr INFO:                 channel_first : False
[2024/04/19 14:50:52] ppocr INFO:                 img_mode : RGB
[2024/04/19 14:50:52] ppocr INFO:             VQATokenLabelEncode : 
[2024/04/19 14:50:52] ppocr INFO:                 algorithm : LayoutXLM
[2024/04/19 14:50:52] ppocr INFO:                 class_path : /opt/waf-ocr/kie_train_data/cin_front/v11/class_list.txt
[2024/04/19 14:50:52] ppocr INFO:                 contains_re : False
[2024/04/19 14:50:52] ppocr INFO:                 order_method : tb-yx
[2024/04/19 14:50:52] ppocr INFO:             VQATokenPad : 
[2024/04/19 14:50:52] ppocr INFO:                 max_seq_len : 512
[2024/04/19 14:50:52] ppocr INFO:                 return_attention_mask : True
[2024/04/19 14:50:52] ppocr INFO:             VQASerTokenChunk : 
[2024/04/19 14:50:52] ppocr INFO:                 max_seq_len : 512
[2024/04/19 14:50:52] ppocr INFO:             Resize : 
[2024/04/19 14:50:52] ppocr INFO:                 size : [224, 224]
[2024/04/19 14:50:52] ppocr INFO:             NormalizeImage : 
[2024/04/19 14:50:52] ppocr INFO:                 mean : [123.675, 116.28, 103.53]
[2024/04/19 14:50:52] ppocr INFO:                 order : hwc
[2024/04/19 14:50:52] ppocr INFO:                 scale : 1
[2024/04/19 14:50:52] ppocr INFO:                 std : [58.395, 57.12, 57.375]
[2024/04/19 14:50:52] ppocr INFO:             ToCHWImage : None
[2024/04/19 14:50:52] ppocr INFO:             KeepKeys : 
[2024/04/19 14:50:52] ppocr INFO:                 keep_keys : ['input_ids', 'bbox', 'attention_mask', 'token_type_ids', 'image', 'labels']
[2024/04/19 14:50:52] ppocr INFO:     loader : 
[2024/04/19 14:50:52] ppocr INFO:         batch_size_per_card : 1
[2024/04/19 14:50:52] ppocr INFO:         drop_last : False
[2024/04/19 14:50:52] ppocr INFO:         num_workers : 1
[2024/04/19 14:50:52] ppocr INFO:         shuffle : False
[2024/04/19 14:50:52] ppocr INFO: Global : 
[2024/04/19 14:50:52] ppocr INFO:     cal_metric_during_train : False
[2024/04/19 14:50:52] ppocr INFO:     distributed : False
[2024/04/19 14:50:52] ppocr INFO:     epoch_num : 200
[2024/04/19 14:50:52] ppocr INFO:     eval_batch_step : [0, 19]
[2024/04/19 14:50:52] ppocr INFO:     infer_img : /opt/waf-ocr/kie_train_data/cin_front/v11/val/0077664544565.JPG
[2024/04/19 14:50:52] ppocr INFO:     log_smooth_window : 10
[2024/04/19 14:50:52] ppocr INFO:     pretrained_model : /opt/waf-ocr/kie_train_data/cin_front/v11/output-mdl/best_accuracy/
[2024/04/19 14:50:52] ppocr INFO:     print_batch_step : 10
[2024/04/19 14:50:52] ppocr INFO:     save_epoch_step : 2000
[2024/04/19 14:50:52] ppocr INFO:     save_inference_dir : /opt/waf-ocr/kie_train_data/cin_front/v11/output-mdl/inference
[2024/04/19 14:50:52] ppocr INFO:     save_model_dir : ./../output/
[2024/04/19 14:50:52] ppocr INFO:     save_res_path : /opt/waf-ocr/kie_train_data/cin_front/v11/output-mdl/
[2024/04/19 14:50:52] ppocr INFO:     seed : 2022
[2024/04/19 14:50:52] ppocr INFO:     use_gpu : True
[2024/04/19 14:50:52] ppocr INFO:     use_visualdl : False
[2024/04/19 14:50:52] ppocr INFO: Loss : 
[2024/04/19 14:50:52] ppocr INFO:     loss_config_list : 
[2024/04/19 14:50:52] ppocr INFO:         DistillationVQASerTokenLayoutLMLoss : 
[2024/04/19 14:50:52] ppocr INFO:             key : backbone_out
[2024/04/19 14:50:52] ppocr INFO:             model_name_list : ['Student', 'Teacher']
[2024/04/19 14:50:52] ppocr INFO:             num_classes : 15
[2024/04/19 14:50:52] ppocr INFO:             weight : 1.0
[2024/04/19 14:50:52] ppocr INFO:         DistillationSERDMLLoss : 
[2024/04/19 14:50:52] ppocr INFO:             act : softmax
[2024/04/19 14:50:52] ppocr INFO:             key : backbone_out
[2024/04/19 14:50:52] ppocr INFO:             model_name_pairs : [['Student', 'Teacher']]
[2024/04/19 14:50:52] ppocr INFO:             use_log : True
[2024/04/19 14:50:52] ppocr INFO:             weight : 1.0
[2024/04/19 14:50:52] ppocr INFO:         DistillationVQADistanceLoss : 
[2024/04/19 14:50:52] ppocr INFO:             key : hidden_states_5
[2024/04/19 14:50:52] ppocr INFO:             mode : l2
[2024/04/19 14:50:52] ppocr INFO:             model_name_pairs : [['Student', 'Teacher']]
[2024/04/19 14:50:52] ppocr INFO:             name : loss_5
[2024/04/19 14:50:52] ppocr INFO:             weight : 0.5
[2024/04/19 14:50:52] ppocr INFO:         DistillationVQADistanceLoss : 
[2024/04/19 14:50:52] ppocr INFO:             key : hidden_states_8
[2024/04/19 14:50:52] ppocr INFO:             mode : l2
[2024/04/19 14:50:52] ppocr INFO:             model_name_pairs : [['Student', 'Teacher']]
[2024/04/19 14:50:52] ppocr INFO:             name : loss_8
[2024/04/19 14:50:52] ppocr INFO:             weight : 0.5
[2024/04/19 14:50:52] ppocr INFO:     name : CombinedLoss
[2024/04/19 14:50:52] ppocr INFO: Metric : 
[2024/04/19 14:50:52] ppocr INFO:     base_metric_name : VQASerTokenMetric
[2024/04/19 14:50:52] ppocr INFO:     key : Student
[2024/04/19 14:50:52] ppocr INFO:     main_indicator : hmean
[2024/04/19 14:50:52] ppocr INFO:     name : DistillationMetric
[2024/04/19 14:50:52] ppocr INFO: Optimizer : 
[2024/04/19 14:50:52] ppocr INFO:     beta1 : 0.9
[2024/04/19 14:50:52] ppocr INFO:     beta2 : 0.999
[2024/04/19 14:50:52] ppocr INFO:     lr : 
[2024/04/19 14:50:52] ppocr INFO:         epochs : 200
[2024/04/19 14:50:52] ppocr INFO:         learning_rate : 5e-05
[2024/04/19 14:50:52] ppocr INFO:         name : Linear
[2024/04/19 14:50:52] ppocr INFO:         warmup_epoch : 10
[2024/04/19 14:50:52] ppocr INFO:     name : AdamW
[2024/04/19 14:50:52] ppocr INFO:     regularizer : 
[2024/04/19 14:50:52] ppocr INFO:         factor : 0.0
[2024/04/19 14:50:52] ppocr INFO:         name : L2
[2024/04/19 14:50:52] ppocr INFO: PostProcess : 
[2024/04/19 14:50:52] ppocr INFO:     class_path : /opt/waf-ocr/kie_train_data/cin_front/v11/class_list.txt
[2024/04/19 14:50:52] ppocr INFO:     key : backbone_out
[2024/04/19 14:50:52] ppocr INFO:     model_name : ['Student', 'Teacher']
[2024/04/19 14:50:52] ppocr INFO:     name : DistillationSerPostProcess
[2024/04/19 14:50:52] ppocr INFO: Train : 
[2024/04/19 14:50:52] ppocr INFO:     dataset : 
[2024/04/19 14:50:52] ppocr INFO:         data_dir : /opt/waf-ocr/kie_train_data/cin_front/v11/train
[2024/04/19 14:50:52] ppocr INFO:         label_file_list : ['/opt/waf-ocr/kie_train_data/cin_front/v11/train.json']
[2024/04/19 14:50:52] ppocr INFO:         name : SimpleDataSet
[2024/04/19 14:50:52] ppocr INFO:         ratio_list : [1.0]
[2024/04/19 14:50:52] ppocr INFO:         transforms : 
[2024/04/19 14:50:52] ppocr INFO:             DecodeImage : 
[2024/04/19 14:50:52] ppocr INFO:                 channel_first : False
[2024/04/19 14:50:52] ppocr INFO:                 img_mode : RGB
[2024/04/19 14:50:52] ppocr INFO:             VQATokenLabelEncode : 
[2024/04/19 14:50:52] ppocr INFO:                 algorithm : LayoutXLM
[2024/04/19 14:50:52] ppocr INFO:                 class_path : /opt/waf-ocr/kie_train_data/cin_front/v11/class_list.txt
[2024/04/19 14:50:52] ppocr INFO:                 contains_re : False
[2024/04/19 14:50:52] ppocr INFO:                 order_method : tb-yx
[2024/04/19 14:50:52] ppocr INFO:             VQATokenPad : 
[2024/04/19 14:50:52] ppocr INFO:                 max_seq_len : 512
[2024/04/19 14:50:52] ppocr INFO:                 return_attention_mask : True
[2024/04/19 14:50:52] ppocr INFO:             VQASerTokenChunk : 
[2024/04/19 14:50:52] ppocr INFO:                 max_seq_len : 512
[2024/04/19 14:50:52] ppocr INFO:             Resize : 
[2024/04/19 14:50:52] ppocr INFO:                 size : [224, 224]
[2024/04/19 14:50:52] ppocr INFO:             NormalizeImage : 
[2024/04/19 14:50:52] ppocr INFO:                 mean : [123.675, 116.28, 103.53]
[2024/04/19 14:50:52] ppocr INFO:                 order : hwc
[2024/04/19 14:50:52] ppocr INFO:                 scale : 1
[2024/04/19 14:50:52] ppocr INFO:                 std : [58.395, 57.12, 57.375]
[2024/04/19 14:50:52] ppocr INFO:             ToCHWImage : None
[2024/04/19 14:50:52] ppocr INFO:             KeepKeys : 
[2024/04/19 14:50:52] ppocr INFO:                 keep_keys : ['input_ids', 'bbox', 'attention_mask', 'token_type_ids', 'image', 'labels']
[2024/04/19 14:50:52] ppocr INFO:     loader : 
[2024/04/19 14:50:52] ppocr INFO:         batch_size_per_card : 1
[2024/04/19 14:50:52] ppocr INFO:         drop_last : False
[2024/04/19 14:50:52] ppocr INFO:         num_workers : 1
[2024/04/19 14:50:52] ppocr INFO:         shuffle : True
[2024/04/19 14:50:52] ppocr INFO: profiler_options : None
[2024/04/19 14:50:52] ppocr INFO: train with paddle 2.5.2 and device Place(gpu:0)
[2024/04/19 14:50:52] ppocr INFO: Initialize indexs of datasets:['/opt/waf-ocr/kie_train_data/cin_front/v11/train.json']
[2024-04-19 14:50:53,039] [    INFO] - Already cached /home/user-dev/.paddlenlp/models/layoutxlm-base-uncased/sentencepiece.bpe.model
[2024-04-19 14:50:53,362] [    INFO] - tokenizer config file saved in /home/user-dev/.paddlenlp/models/layoutxlm-base-uncased/tokenizer_config.json
[2024-04-19 14:50:53,362] [    INFO] - Special tokens file saved in /home/user-dev/.paddlenlp/models/layoutxlm-base-uncased/special_tokens_map.json
[2024/04/19 14:50:53] ppocr INFO: Initialize indexs of datasets:['/opt/waf-ocr/kie_train_data/cin_front/v11/val.json']
[2024-04-19 14:50:53,363] [    INFO] - Already cached /home/user-dev/.paddlenlp/models/layoutxlm-base-uncased/sentencepiece.bpe.model
[2024-04-19 14:50:53,695] [    INFO] - tokenizer config file saved in /home/user-dev/.paddlenlp/models/layoutxlm-base-uncased/tokenizer_config.json
[2024-04-19 14:50:53,695] [    INFO] - Special tokens file saved in /home/user-dev/.paddlenlp/models/layoutxlm-base-uncased/special_tokens_map.json
[2024-04-19 14:50:53,697] [ WARNING] - You are using a model of type layoutlmv2 to instantiate a model of type layoutxlm. This is not supported for all configurations of models and can yield errors.
[2024-04-19 14:50:53,697] [    INFO] - Already cached /home/user-dev/.paddlenlp/models/vi-layoutxlm-base-uncased/model_state.pdparams
[2024-04-19 14:50:53,697] [    INFO] - Loading weights file model_state.pdparams from cache at /home/user-dev/.paddlenlp/models/vi-layoutxlm-base-uncased/model_state.pdparams
[2024-04-19 14:50:54,566] [    INFO] - Loaded weights file from disk, setting weights to model.
W0419 14:50:54.568512 4044360 gpu_resources.cc:119] Please NOTE: device: 0, GPU Compute Capability: 8.6, Driver API Version: 12.4, Runtime API Version: 11.8
W0419 14:50:54.591214 4044360 gpu_resources.cc:149] device: 0, cuDNN Version: 8.7.
[2024-04-19 14:50:55,319] [ WARNING] - Some weights of the model checkpoint at vi-layoutxlm-base-uncased were not used when initializing LayoutXLMModel: ['visual.pixel_mean', 'visual.pixel_std', 'visual_proj.bias', 'visual_proj.weight']
- This IS expected if you are initializing LayoutXLMModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing LayoutXLMModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
[2024-04-19 14:50:55,319] [    INFO] - All the weights of LayoutXLMModel were initialized from the model checkpoint at vi-layoutxlm-base-uncased.
If your task is similar to the task the model of the checkpoint was trained on, you can already use LayoutXLMModel for predictions without further training.
kwargs {'num_classes': 15}
kwargs 15
Traceback (most recent call last):
  File "/opt/waf-ocr/PaddleOCR/deploy/slim/quantization/quant.py", line 202, in <module>
    main(config, device, logger, vdl_writer)
  File "/opt/waf-ocr/PaddleOCR/deploy/slim/quantization/quant.py", line 157, in main
    model = build_model(config['Architecture'])
  File "/opt/waf-ocr/PaddleOCR/ppocr/modeling/architectures/__init__.py", line 34, in build_model
    arch = getattr(mod, name)(config)
  File "/opt/waf-ocr/PaddleOCR/ppocr/modeling/architectures/distillation_model.py", line 47, in __init__
    model = BaseModel(model_config)
  File "/opt/waf-ocr/PaddleOCR/ppocr/modeling/architectures/base_model.py", line 55, in __init__
    self.backbone = build_backbone(config["Backbone"], model_type)
  File "/opt/waf-ocr/PaddleOCR/ppocr/modeling/backbones/__init__.py", line 74, in build_backbone
    module_class = eval(module_name)(**config)
  File "/opt/waf-ocr/PaddleOCR/ppocr/modeling/backbones/vqa_layoutlm.py", line 151, in __init__
    super(LayoutXLMForSer, self).__init__(
  File "/opt/waf-ocr/PaddleOCR/ppocr/modeling/backbones/vqa_layoutlm.py", line 67, in __init__
    self.model = model_class(
  File "/opt/kie2/kie/lib/python3.10/site-packages/paddlenlp/transformers/utils.py", line 255, in __impl__
    init_func(self, *args, **kwargs)
TypeError: LayoutXLMForTokenClassification.__init__() got an unexpected keyword argument 'num_classes'

pxike avatar Apr 19 '24 13:04 pxike

切换到main分支重新运行一下吧

zhangyubo0722 avatar Apr 24 '24 08:04 zhangyubo0722