Skip to content

[Build] TypeInferenceError when quantize an onnx model with custom operator #23191

@Lhy-opt

Description

@Lhy-opt

Describe the issue

I use onnxruntime python api to quantize a model with custom operator.

@onnx_op was used in my code to register the custom op:

@onnx_op(op_type='LocatePostNms',
domain='ai.onnx.contrib',
inputs=[PyCustomOpDef.dt_float, PyCustomOpDef.dt_int32, PyCustomOpDef.dt_float, PyCustomOpDef.dt_float,
PyCustomOpDef.dt_int32, PyCustomOpDef.dt_float],
outputs=[PyCustomOpDef.dt_float, PyCustomOpDef.dt_int32],
attrs={"classNumber": PyCustomOpDef.dt_int32,
"iou_thresh": PyCustomOpDef.dt_float,
"scale": PyCustomOpDef.dt_double,
"side": PyCustomOpDef.dt_int32,
"topk": PyCustomOpDef.dt_int32,
"type": PyCustomOpDef.dt_int32}
)
def locatepostnms_compute(x, **kwargs):
padded_box = np.ones((1, 24000, 7))
result_cnt = np.ones(1)
return padded_box, result_cnt

and set sess_options.register_custom_ops_library(get_library_path()), but error happened when running onnxruntime. quantization. quantize. quantize_static interface, report:

onnx.onnx_cpp2py_export.shape_inference.InferenceError: [TypeInferenceError] Cannot infer type and shape for node name 453. No opset import for domain ai.onnx.contrib optype LocatePostNms

where 453 is the name of custom op, how do i infer type and shape for this type of onnx model to finish the quantization?

Sorry that i can't provide the model

Urgency

No response

Target platform

windows 11 PRO/ ubuntu 22.04

Build script

python

Error / output

onnx.onnx_cpp2py_export.shape_inference.InferenceError: [TypeInferenceError] Cannot infer type and shape for node name 453. No opset import for domain ai.onnx.contrib optype LocatePostNms

Visual Studio Version

No response

GCC / Compiler Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    buildbuild issues; typically submitted using templatequantizationissues related to quantizationstaleissues that have not been addressed in a while; categorized by a bot

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions