breezedeus / CnOCR

CnOCR: Awesome Chinese/English OCR Python toolkits based on PyTorch. It comes with 20+ well-trained models for different application scenarios and can be used directly after installation. 【基于 PyTorch/MXNet 的中文/英文 OCR Python 包。】
https://www.breezedeus.com/article/cnocr
Apache License 2.0
3.28k stars 507 forks source link

Failed to export densenet_lite_136-gru onnx format #311

Closed sif-boudjellal closed 10 months ago

sif-boudjellal commented 10 months ago

Hello CnOCR Community,

I got this error when I tried to export the trained weights to Onnx.

! cnocr export-onnx -m densenet_lite_136-gru -i /content/cnocr-v2.3-densenet_lite_136-gru-model.ckpt  -o densenet_lite_136-gru-model.onnx

The Error

RuntimeError: Error(s) in loading state_dict for OcrModel:
    size mismatch for linear.weight: copying a param with shape torch.Size([38, 256]) from checkpoint, the shape in current model is torch.Size([6683, 256]).
    size mismatch for linear.bias: copying a param with shape torch.Size([38]) from checkpoint, the shape in current model is torch.Size([6683]).
breezedeus commented 10 months ago
size mismatch for linear.weight: copying a param with shape torch.Size([38, 256]) from checkpoint, the shape in current model is torch.Size([6683, 256]).

I assume you are using a new vocab, then you need to pass in the vocab file path when using export-onnx:

cnocr export-onnx -m densenet_lite_136-gru -v <path/to/vocab.txt> ...