yobx.tensorflow.ops.conv#

Converter for the TF Conv2D op → ONNX Conv.

TensorFlow Conv2D uses:

  • Input layout: NHWC (batch, height, width, channels)

  • Filter layout: HWIO (kernel_h, kernel_w, in_channels, out_channels)

ONNX Conv expects:

  • X layout: NCHW (batch, channels, height, width)

  • W layout: OIHW (out_channels, in_channels, kernel_h, kernel_w)

The converter inserts Transpose nodes to bridge the two conventions:

  1. Input: NHWC → NCHW (perm=[0, 3, 1, 2])

  2. Filter: HWIO → OIHW (perm=[3, 2, 0, 1])

  3. ONNX Conv is emitted.

  4. Output: NCHW → NHWC (perm=[0, 2, 3, 1])

Padding is expressed as explicit pads rather than auto_pad so that ONNX shape inference can propagate output shapes even when the batch dimension is dynamic.

yobx.tensorflow.ops.conv.convert_conv2d(g: GraphBuilderExtendedProtocol, sts: Dict[str, Any], outputs: List[str], op: Operation) str[source]#

Converts TF Conv2D (NHWC / HWIO) → ONNX Conv (NCHW / OIHW).

Dilations and strides are extracted from the 4-element NHWC-ordered attribute lists; only the spatial components (indices 1 and 2) are forwarded to the ONNX node. Padding is expressed as explicit pads so that ONNX shape inference works with a dynamic batch dimension.