Gmgge / TrOCR-Seal-Recognition

基于transformer的ocr识别,在公章(印章识别, seal recognition)拓展应用
121 stars 24 forks source link

章识别模型运行错误, #4

Closed TPL-egg-HIT closed 8 months ago

TPL-egg-HIT commented 11 months ago

我使用您提供的链接下载了对应的模型权重,解压后如下结构 34M decoder_model.onnx 85M encoder_model.onnx 45K vocab.json

使用了您建议的运行指令: python onnx_test.py --model /xxx/seal --test_img /xxx/seal_fake.jpeg

首先遇到第一个错误: Traceback (most recent call last): File "onnx_test.py", line 131, in res = model.run(img) File "onnx_test.py", line 109, in run if pred[-1] == self.vocab[""]: ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

我看了下输出没问题,代码是控制循环停止的,暂时没啥影响,就禁掉了。

继续运行代码,然后又遇到下面第二个错误: Traceback (most recent call last): File "onnx_test.py", line 135, in res = model.run(img) File "onnx_test.py", line 102, in run decoder_output = self.decoder(input_ids=input_ids, File "onnx_test.py", line 74, in call onnx_output = self.model.run(['logits'], onnx_inputs) File "/opt/conda/lib/python3.8/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 192, in run return self._sess.run(output_names, input_feed, run_options) onnxruntime.capi.onnxruntime_pybind11_state.InvalidArgument: [ONNXRuntimeError] : 2 : INVALID_ARGUMENT : Unexpected input data type. Actual: (tensor(string)) , expected: (tensor(int64))

报错位置的代码,如下: onnx_inputs = {"input_ids": input_ids, "attention_mask": attention_mask, "encoder_hidden_states": encoder_hidden_states} print('onnx_inputs', onnx_inputs['input_ids'].shape) print('onnx_inputs', onnx_inputs['attention_mask'].shape) print('onnx_inputs', onnx_inputs['encoder_hidden_states'].shape) onnx_output = self.model.run(['logits'], onnx_inputs)

我把报错位置的数据打印看了下,感觉并没有问题呀,输入格式完成符合预期,如下: onnx_inputs (1, 1) onnx_inputs (1, 1) onnx_inputs (1, 578, 384) [[ 3.1568584e+01 -1.5170749e+01 -1.3366631e-02 ... -2.6361866e+00 -5.3458900e+00 1.1954393e+00]] [[1.0000000e+00 5.0276506e-21 1.9236803e-14 ... 1.3965480e-15 9.2949584e-17 6.4433281e-14]] (1, 3584) ids [0] onnx_test.py:103: VisibleDeprecationWarning: Creating an ndarray from ragged nested sequences (which is a list-or-tuple of lists-or-tuples-or ndarrays with different lengths or shapes) is deprecated. If you meant to do this, you must specify 'dtype=object' when creating the ndarray. input_ids = np.array([ids]) onnx_inputs (1, 2) onnx_inputs (1, 2) onnx_inputs (1, 578, 384)

麻烦大佬帮忙看下,谢谢~~

Gmgge commented 11 months ago

感谢你的测试,我已更新解码逻辑,请尝试该问题是否被解决。

如果可以,请贴出你的pip list,这样以便问题仍然存在时,我进行进一步测试。

根据你的有效反馈,我这边邀请你共同维护该项目,期待你的回复。