chineseocr / trocr-chinese

transformers ocr for chinese
330 stars 49 forks source link

onnxruntime 转换报错 #40

Open duyuankai1992 opened 1 year ago

duyuankai1992 commented 1 year ago

执行命令:python -m transformers.onnx --model weights/hand-write --feature=vision2seq-lm onnx/ transformers: 4.30.2 onnxrun:1.14.1 image

onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Reshape node. Name:'Reshape_53' Status Message: /onnxruntime_src/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:40 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape&, onnxruntime::TensorShapeVector&, bool) gsl::narrow_cast(input_shape.Size()) == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{3,578,384}, requested shape:{2,578,6,64}

LUXUS1 commented 11 months ago

可以使用optimum-cli进行转换 1、pip install optimum[exporters] 2、其他环境版本:pytorch=2.0.0 onnx=1.14.1 3、转换命令:optimum-cli export onnx --model weights/weights/ --task image-to-text --opset 18 onnx_test/ 其中--model weights/weights/为模型路径,--opset 18可选,onnx_test/为保存路径

LaplaTom commented 9 months ago

您好,我执行第一个作者的命令可以转换成功,但是在测试的时候会提示 onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Invalid Feed Input Name:attention_mask

采用optimum-cli转换的话,是这个问题 UnboundLocalError: local variable 'all_files' referenced before assignment

LUXUS1 commented 9 months ago

这个问题我没遇到过,哈哈。你可以更换一下torch或者opset的版本试一下。

jonesky commented 1 month ago

请教大佬,后面有解决吗?遇到同样的问题