The current ONNX2TORCH assumes that all weights are available through the model.graph.initializer, but this is not true for ONNX files generated by PaddleOCR .
I solved this by adding the following code in model.py:
if len(onnx_model.graph.initializer) == 0:
new_initializers = []
for node in onnx_model.graph.node:
if node.op_type == "Constant":
for attr in node.attribute:
if attr.name == "value":
new_initializers.append(attr.t)
onnx_model.graph.initializer.extend(new_initializers)
Then the conversion worked flawlessly with onnx2torch (while onnx2pytorch still failed), good job!