PaddleOCR2Pytorch icon indicating copy to clipboard operation
PaddleOCR2Pytorch copied to clipboard

请问能否用较明确的paddle和torch版本维护一下这个项目?

Open ywh-my opened this issue 11 months ago • 8 comments

实在是跑不通。。。不知道这些库要安装什么版本,希望能转换所有的 ppocr v4的模型

ywh-my avatar Apr 06 '25 13:04 ywh-my

是的,需要版本信息,现在一个也跑不通

zzk2021 avatar Apr 16 '25 08:04 zzk2021

@ywh-my @zzk2021 你们什么版本,哪一步跑不通,跑不通是报了什么错? paddle 2.x pytorch 1.x (2.x的低版本可能也行)

frotms avatar Apr 16 '25 09:04 frotms

我是pytorch 2.6 ,但是numpy的版本好像也有要求? 此外我在运行ppocr v4的det推理时 (MinerU) PS F:\TableStructureRec-main\PaddleOCR2Pytorch-main> python tools/infer/predict_det.py --image_dir "F:\TableStructureRec-main\tools\07d6c3c994db5aa77b8bd71d96f92157fa6e9b58618ef9b7fd500f2cf021af2b .jpg" --det_model_path ch_PP-OCRv4_det_infer.pth --rec_yaml_p ath configs/det/ch_PP-OCRv4/ch_PP-OCRv4_det_student.yml

  size mismatch for backbone.conv1.conv.weight: copying a param with shape torch.Size([16, 3, 3, 3]) from checkpoint, the shape in current model is torch.Size([8, 3, 3, 3]).
    size mismatch for backbone.conv1.bn.weight: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([8]).
    size mismatch for backbone.conv1.bn.bias: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([8]).
    size mismatch for backbone.conv1.bn.running_mean: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([8]).
    size mismatch for backbone.conv1.bn.running_var: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([8]).

会爆键值对不匹配的错误

zzk2021 avatar Apr 17 '25 01:04 zzk2021

您说的 “”paddle 2.x pytorch 1.x (2.x的低版本可能也行)“” 这种版本比较老了,我们现在项目一般用paddleocr=2.10.0 ,paddlepaddlegpu=3.0.0.rc1 ,torch >=2.4.0 , 若您有时间和精力,希望可以用最新的这些主要库 试试代码能不能跑通

ywh-my avatar Apr 17 '25 01:04 ywh-my

我是pytorch 2.6 ,但是numpy的版本好像也有要求? 此外我在运行ppocr v4的det推理时 (MinerU) PS F:\TableStructureRec-main\PaddleOCR2Pytorch-main> python tools/infer/predict_det.py --image_dir "F:\TableStructureRec-main\tools\07d6c3c994db5aa77b8bd71d96f92157fa6e9b58618ef9b7fd500f2cf021af2b .jpg" --det_model_path ch_PP-OCRv4_det_infer.pth --rec_yaml_p ath configs/det/ch_PP-OCRv4/ch_PP-OCRv4_det_student.yml

  size mismatch for backbone.conv1.conv.weight: copying a param with shape torch.Size([16, 3, 3, 3]) from checkpoint, the shape in current model is torch.Size([8, 3, 3, 3]).
    size mismatch for backbone.conv1.bn.weight: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([8]).
    size mismatch for backbone.conv1.bn.bias: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([8]).
    size mismatch for backbone.conv1.bn.running_mean: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([8]).
    size mismatch for backbone.conv1.bn.running_var: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([8]).

会爆键值对不匹配的错误

是--det_yaml_path,不是rec_yaml_path python ./tools/infer/predict_det.py --image_dir "F:\TableStructureRec-main\tools\07d6c3c994db5aa77b8bd71d96f92157fa6e9b58618ef9b7fd500f2cf021af2b .jpg" --det_model_path your_ch_ptocr_v4_det_infer_path.pth --det_yaml_path ./configs/det/ch_PP-OCRv4/ch_PP-OCRv4_det_student.yml

frotms avatar Apr 17 '25 02:04 frotms

您说的 “”paddle 2.x pytorch 1.x (2.x的低版本可能也行)“” 这种版本比较老了,我们现在项目一般用paddleocr=2.10.0 ,paddlepaddlegpu=3.0.0.rc1 ,torch >=2.4.0 , 若您有时间和精力,希望可以用最新的这些主要库 试试代码能不能跑通

torch版本都能跑,paddlepaddle3.0接口有改动。 可以先临时这么用: 转模型: 一种方式是用旧的环境去转模型 还一种方式是转模型代码修改:

    #import paddle.fluid as fluid
    #with fluid.dygraph.guard():
    #    para_state_dict, opti_state_dict = fluid.load_dygraph(weights_path)
    #改成
    import paddle
    para_state_dict = paddle.load(f'{weights_path}.pdparams')


    #self.net.state_dict()[ptname].copy_(torch.Tensor(v))的torch.Tensor(v)
    #改成
    self.net.state_dict()[ptname].copy_(torch.Tensor(v.cpu().numpy()))

推理:numpy有更新,需要np.int都改成np.int32

后面有时间会适配新的

frotms avatar Apr 17 '25 04:04 frotms

我是pytorch 2.6 ,但是numpy的版本好像也有要求? 此外我在运行ppocr v4的det推理时 (MinerU) PS F:\TableStructureRec-main\PaddleOCR2Pytorch-main> python tools/infer/predict_det.py --image_dir "F:\TableStructureRec-main\tools\07d6c3c994db5aa77b8bd71d96f92157fa6e9b58618ef9b7fd500f2cf021af2b .jpg" --det_model_path ch_PP-OCRv4_det_infer.pth --rec_yaml_p ath configs/det/ch_PP-OCRv4/ch_PP-OCRv4_det_student.yml

  size mismatch for backbone.conv1.conv.weight: copying a param with shape torch.Size([16, 3, 3, 3]) from checkpoint, the shape in current model is torch.Size([8, 3, 3, 3]).
    size mismatch for backbone.conv1.bn.weight: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([8]).
    size mismatch for backbone.conv1.bn.bias: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([8]).
    size mismatch for backbone.conv1.bn.running_mean: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([8]).
    size mismatch for backbone.conv1.bn.running_var: copying a param with shape torch.Size([16]) from checkpoint, the shape in current model is torch.Size([8]).

会爆键值对不匹配的错误

是--det_yaml_path,不是rec_yaml_path python ./tools/infer/predict_det.py --image_dir "F:\TableStructureRec-main\tools\07d6c3c994db5aa77b8bd71d96f92157fa6e9b58618ef9b7fd500f2cf021af2b .jpg" --det_model_path your_ch_ptocr_v4_det_infer_path.pth --det_yaml_path ./configs/det/ch_PP-OCRv4/ch_PP-OCRv4_det_student.yml

是我疏忽了,现在确实能跑了

zzk2021 avatar Apr 17 '25 05:04 zzk2021