Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Onnx Onnx Helper Make Node

From Leeroopedia


Knowledge Sources
Domains Model_Construction, Computation_Graph
Last Updated 2026-02-10 00:00 GMT

Overview

Concrete tool for constructing computation operator nodes provided by the ONNX helper module.

Description

The make_node function constructs a NodeProto protobuf message representing a single computation operation in the ONNX graph. It accepts the operator type, input/output edge names, and optional attributes as keyword arguments. Attributes are converted to AttributeProto messages via the internal make_attribute function, supporting integers, floats, strings, tensors, graphs, and their repeated variants.

Usage

Import this function when you need to define computation steps in an ONNX model. Call it once per operation, passing the operator name from the ONNX spec (e.g., "Relu", "Conv", "Add"), the input tensor names, and the output tensor names. Operator-specific parameters (like kernel_shape for Conv) are passed as keyword arguments.

Code Reference

Source Location

  • Repository: onnx
  • File: onnx/helper.py
  • Lines: 133-179

Signature

def make_node(
    op_type: str,
    inputs: Sequence[str],
    outputs: Sequence[str],
    name: str | None = None,
    doc_string: str | None = None,
    domain: str | None = None,
    overload: str | None = None,
    **kwargs: Any,
) -> NodeProto:
    """Construct a NodeProto.

    Args:
        op_type: The name of the operator to construct (e.g., "Relu", "Conv").
        inputs: List of input edge names.
        outputs: List of output edge names.
        name: Optional unique identifier for the node.
        doc_string: Optional documentation string.
        domain: Optional operator domain (default is "" for standard ONNX ops).
        overload: Optional field for resolving model-local function calls.
        **kwargs: Operator attributes passed to make_attribute.
    """

Import

from onnx import helper

I/O Contract

Inputs

Name Type Required Description
op_type str Yes ONNX operator name (e.g., "Relu", "Conv", "MatMul")
inputs Sequence[str] Yes List of input tensor edge names
outputs Sequence[str] Yes List of output tensor edge names
name str or None No Optional unique node identifier
domain str or None No Operator domain (default: "" for ai.onnx)
**kwargs Any No Operator-specific attributes (e.g., kernel_shape, pads)

Outputs

Name Type Description
return NodeProto Protobuf message representing a single computation node

Usage Examples

Simple Activation Node

from onnx import helper

# Create a Relu activation node
relu_node = helper.make_node(
    "Relu",           # op_type
    ["X"],            # inputs
    ["Y"],            # outputs
    name="relu0"      # optional name
)

Node with Attributes

from onnx import helper

# Create a Conv node with kernel shape and padding attributes
conv_node = helper.make_node(
    "Conv",
    inputs=["X", "W", "B"],
    outputs=["Y"],
    kernel_shape=[3, 3],
    pads=[1, 1, 1, 1],
    strides=[1, 1],
)

# Create an Add node (element-wise addition)
add_node = helper.make_node(
    "Add",
    inputs=["A", "B"],
    outputs=["C"],
)

Related Pages

Implements Principle

Requires Environment

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment