Skip to content

graph.initializers[weights_value_name] KeyError, because ONNX without graph.initializer (inc. Sollution) #243

@kdirkjan

Description

@kdirkjan

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions