2

I read the ONNX ML documentation at https://github.com/onnx/onnx/blob/master/docs/Operators-ml.md but do not see how to import these functions into my project. I have several upstream nodes generated to do some data splitting & scaling, and I'd like to add one of these ML Operators as another node in my ONNX graph.

It seems this should be incredibly straightforward, but for the life of me I cannot see how it's done.

I would have thought the syntax would be something like:

nodeX = onnx.helper.make_node(
    'Scaler',
    inputs=['Q2'],
    outputs=['Q22'],
    scale=5.0,
    offset = 12.0
)

But, I get the following error: Error in Node: : No Op registered for Scaler with domain_version of 12

So it doesn't seem to recognize the ML operators. Based on the documentation at https://github.com/onnx/onnx/blob/master/docs/Overview.md I set my environment variable ONNX_ML=1, and tried to re-install, but that didn't help.

desertnaut
  • 57,590
  • 26
  • 140
  • 166
Douglas Daly
  • 85
  • 10

1 Answers1

3

Apparently 2 things are required. First - specify the operator domain when creating the node:

nodeX = onnx.helper.make_node(
    'Scaler',
    inputs=['Q2'],
    outputs=['Q22'],
    scale=5.0,
    offset = 12.0,
    domain='ai.onnx.ml'
)

Second - import the domain when creating the model:

model = onnx.helper.make_model(
    graph,
    opset_imports=[
        onnx.helper.make_opsetid('ai.onnx.ml', 1), 
        onnx.helper.make_opsetid('', 14)],
)