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
43.92k stars 7.8k forks source link

使用export_model导出SDMGR模型失败 #13556

Open TrioTea opened 3 months ago

TrioTea commented 3 months ago

Search before asking

Bug

模型的训练、评估和预测均正常运行

(haobin_paddle_ocr_env) (base) [root@localhost PaddleOCR]# python3 tools/export_model.py -c output/kie_60/config.yml -o Architecture.Backbone.checkpoints=output/kie_60/best_accuracy
ERROR:albumentations.check_version:Error fetching version info
Traceback (most recent call last):
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/albumentations/check_version.py", line 32, in fetch_version_info
    data = response.read()
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/http/client.py", line 472, in read
    s = self._safe_read(self.length)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/http/client.py", line 613, in _safe_read
    data = self.fp.read(amt)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/socket.py", line 669, in readinto
    return self._sock.recv_into(b)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/ssl.py", line 1274, in recv_into
    return self.read(nbytes, buffer)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/ssl.py", line 1132, in read
    return self._sslobj.read(len, buffer)
socket.timeout: The read operation timed out
W0731 17:03:00.388967 42736 gpu_resources.cc:119] Please NOTE: device: 0, GPU Compute Capability: 7.5, Driver API Version: 12.4, Runtime API Version: 11.8
W0731 17:03:00.390235 42736 gpu_resources.cc:164] device: 0, cuDNN Version: 8.9.
[2024/07/31 17:03:00] ppocr INFO: train from scratch
Traceback (most recent call last):
  File "tools/export_model.py", line 300, in <module>
    main()
  File "tools/export_model.py", line 294, in main
    export_single_model(
  File "tools/export_model.py", line 197, in export_single_model
    paddle.jit.save(model, save_path)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/paddle/base/wrapped_decorator.py", line 26, in __impl__
    return wrapped_func(*args, **kwargs)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/paddle/jit/api.py", line 809, in wrapper
    func(layer, path, input_spec, **configs)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/paddle/base/wrapped_decorator.py", line 26, in __impl__
    return wrapped_func(*args, **kwargs)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/paddle/base/dygraph/base.py", line 68, in __impl__
    return func(*args, **kwargs)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/paddle/jit/api.py", line 1104, in save
    static_func.concrete_program_specify_input_spec(
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 986, in concrete_program_specify_input_spec
    concrete_program, _ = self.get_concrete_program(
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 875, in get_concrete_program
    concrete_program, partial_program_layer = self._program_cache[
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 1648, in __getitem__
    self._caches[item_id] = self._build_once(item)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 1575, in _build_once
    concrete_program = ConcreteProgram.from_func_spec(
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/decorator.py", line 232, in fun
    return caller(func, *(extras + args), **kw)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/paddle/base/wrapped_decorator.py", line 26, in __impl__
    return wrapped_func(*args, **kwargs)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/paddle/base/dygraph/base.py", line 68, in __impl__
    return func(*args, **kwargs)
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/paddle/jit/dy2static/program_translator.py", line 1346, in from_func_spec
    error_data.raise_new_exception()
  File "/root/anaconda3/envs/haobin_paddle_ocr_env/lib/python3.8/site-packages/paddle/jit/dy2static/error.py", line 452, in raise_new_exception
    raise new_exception from None
AttributeError: In transformed code:

    File "/haobin/code_repo/PaddleOCR/ppocr/modeling/architectures/base_model.py", line 84, in forward
        if self.use_backbone:
    File "/haobin/code_repo/PaddleOCR/ppocr/modeling/architectures/base_model.py", line 85, in forward
        x = self.backbone(x)
    File "/haobin/code_repo/PaddleOCR/ppocr/modeling/backbones/kie_unet_sdmgr.py", line 190, in forward
        img, relations, texts, gt_bboxes = self.pre_process(
    File "/haobin/code_repo/PaddleOCR/ppocr/modeling/backbones/kie_unet_sdmgr.py", line 156, in pre_process
        def pre_process(self, img, relations, texts, gt_bboxes, tag, img_size):
            img, relations, texts, gt_bboxes, tag, img_size = (
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
                img.numpy(),
                relations.numpy(),

    AttributeError: 'Variable' object has no attribute 'tolist'

(haobin_paddle_ocr_env) (base) [root@localhost PaddleOCR]# 

Environment

Minimal Reproducible Example

No response

Additional

No response

Are you willing to submit a PR?

SWHL commented 3 months ago

需要提供具体环境信息,也就是Environment

TrioTea commented 3 months ago

需要提供具体环境信息,明确环境

你好,我添加了环境的描述

SWHL commented 3 months ago

从提供信息来看,似乎是前处理有问题。需要你这里再仔细debug一下具体是哪里导致的。我这里看着是不能复现。

GreatV commented 3 months ago

有些模型目前不支持导出静态图,需要修改模型结构。建议去paddle框架仓库提一个issue。

TrioTea commented 3 months ago

从提供信息来看,似乎是前处理有问题。需要你这里再仔细debug一下具体是哪里导致的。我这里看着是不能复现。

我尝试使用wildreceipt数据集进行训练后尝试导出成推理模型,也遇到了同样的错误

SWHL commented 3 months ago

试试导出官方提供的模型呢?

TrioTea commented 3 months ago

试试导出官方提供的模型呢?

尝试直接下载了https://paddlepaddle.github.io/PaddleOCR/algorithm/kie/algorithm_kie_sdmgr.html?h=sdmgr的训练模型进行导出,也遇到了同样的错误

TrioTea commented 3 months ago

有些模型目前不支持导出静态图,需要修改模型结构。建议去paddle框架仓库提一个issue。

尝试了paddle 3.0的beta版,问题暂时也还没有解决

GreatV commented 3 months ago

@TeaWu 这个得修改模型代码,或者等待paddle框架适配。参考 https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/jit/limitations_cn.html

TrioTea commented 3 months ago

@TeaWu这个得修改模型代码,或者等待paddle框架装备。参考https://www.paddlepaddle.org.cn/documentation/docs/zh/develop/guides/jit/limitations_cn.html

试了一下修改模型的代码,对我来说难度比较大,一直没成功