Skip to content

[Feature][Relax][ONNX] Support CenterCropPad operator in Relax ONNX frontend #20971

Open

Description

@Chaitanya140904

Feature Description

Support the ONNX CenterCropPad operator in the Apache TVM Relax ONNX frontend (python/tvm/relax/frontend/onnx/onnx_frontend.py).

Motivation

CenterCropPad crops and/or pads input tensors centered along specified axes to reach a desired spatial shape. It is a standard building block in computer vision data pipelines and end-to-end vision inference models where image preprocessing is embedded directly into the ONNX graph.

Standardized in ONNX opset 18+, CenterCropPad is currently not supported in the Relax ONNX frontend, resulting in:

NotImplementedError: The following operators are not supported: ['CenterCropPad']

This operator was also highlighted in the ONNX operator coverage RFC tracking issue #20124 under Cropping / Sequence operators.

Operator Specification (ONNX Opset 18+)

  • Inputs:
    1. input_data: N-D input tensor (float32, float16, uint8, etc.).
    2. shape: 1D integer tensor specifying the target shape along the specified axes.
  • Attributes:
    • axes: list of ints (optional) - the axes along which to crop/pad (defaults to [-2, -1] for spatial dims).
  • Outputs:
    1. output_data: Cropped and/or padded tensor matching the target shape.

Expected Behavior

The Relax ONNX frontend should implement CenterCropPad by comparing input dimensions with target dimensions:

  1. For dimensions where target < input: compute symmetric start/end indices and apply relax.op.strided_slice.
  2. For dimensions where target > input: compute symmetric left/right pad widths and apply relax.op.pad.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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