Skip to content

When I quantize the yolo_tube.onnx model, the scale_ array tensor for bias was a scalar, so an exception was thrown #581

@happyAnger66-an

Description

@happyAnger66-an

if scale_array.shape and scale_array.shape[0] != weight_shape[axis]:

Traceback (most recent call last):
File "/usr/local/lib/python3.10/dist-packages/modelopt/onnx/quantization/qdq_utils.py", line 781, in qdq_to_dq
scaled = _convert_weight(weight_array, scale, zp, quantized_node)
File "/usr/local/lib/python3.10/dist-packages/modelopt/onnx/quantization/qdq_utils.py", line 676, in _convert_weight
reshape_dims[axis] = scale_array.shape[0]
IndexError: tuple index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/srcs/codes/wujie/model-optimizer/./src/model_optimizer/quantization/models/yolo.py", line 114, in
quantize_model_onnx(model, quant_cfg, quant_mode, args)
File "/srcs/codes/wujie/model-optimizer/./src/model_optimizer/quantization/models/yolo.py", line 39, in quantize_model_onnx
quantize(
File "/usr/local/lib/python3.10/dist-packages/modelopt/onnx/quantization/quantize.py", line 523, in quantize
onnx_model = qdq_to_dq(onnx_model)
File "/usr/local/lib/python3.10/dist-packages/modelopt/onnx/quantization/qdq_utils.py", line 806, in qdq_to_dq
raise RuntimeError(f"Failed to convert node {node.name}: {e!s}")
RuntimeError: Failed to convert node /model.23/cv3.0/cv3.0.2/weight_quantizer/QuantizeLinear: tuple index out of range

After adding the following code, the problem can be fixed
scale_array = onnx.numpy_helper.to_array(scale)
if not scale_array.shape: ### ---------this is my added
scale_array = np.expand_dims(scale_array, axis=0)
print(f'none scale found extend to {scale_array}')

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