Skip to content

Bug: Error converting Resize operator with scales/sizes as inputs (opset 11+) #7

@lksrz

Description

@lksrz

Hi @Oil3,
Thanks for creating this converter!
While converting an ONNX model (yolo6's pt exported to onnx in my case, but likely applicable to others) using the convert.py script, I encountered an error during the processing of a Resize operator (opset 11 or later).
Error:
Initially, an UnboundLocalError: local variable 'scale' referenced before assignment occurred within the _convert_resize function in _operators_nd.py. This happened because the scales parameter for the Resize operation was provided as an input tensor (standard for opset 11+) rather than an attribute. The code attempted to access the scale variable before it was assigned a value from the input tensor.
During the fix attempt, an AttributeError related to graph.has_initializer also occurred, indicating the need to use node.input_tensors for accessing input values.
Root Cause:
The current implementation of _convert_resize doesn't fully handle the case where scales or sizes are provided as input tensors (indices 2 and 3 respectively in opset 11+) instead of attributes (opset 10 style).
Proposed Solution:
Modify _convert_resize to first check node.input_tensors for the presence of scales and sizes input names. If found, retrieve the values from there. If not found, then fall back to checking the node attributes (node.attrs.get('scales', None)).
I have tested a fix locally which resolves this issue for my model. I will link a Pull Request.
Best!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions