[Tracking Issue] Add missing vision/image operators
Background
Since we phased out Relay in early 2025, several vision/image operators that Relay supported are missing from Relax, blocking deployment of common detection and segmentation models (Faster R-CNN, Mask R-CNN, Spatial Transformer Networks, etc.).
Currently Relax only has 3 vision/image ops: all_class_non_max_suppression, resize2d, grid_sample.
Scope
Each operator needs:
- TOPI compute (
python/tvm/topi/) — if not already present - Relax op registration — C++ attrs + struct info inference (
src/relax/op/,include/tvm/relax/attrs/) + Python wrapper (python/tvm/relax/op/) - Legalization (
python/tvm/relax/transform/legalize_ops/) - Frontend integration — update ONNX/PyTorch/TFLite frontends to emit the new op
- Tests — op-level unit tests + frontend integration tests
Steps 1–3 (Relax op) and step 4 (frontend) can be done in separate PRs or combined — contributors can choose based on scope.
Operators
Tier 1 — Unblocks mainstream detection/segmentation models
- [x]
roi_align— Core op for Faster R-CNN, Mask R-CNN, Cascade R-CNN. TOPI was removed during te.schedule phase-out, needs full reimplementation. - [x]
affine_grid— Generates sampling grid for Spatial Transformer Networks. TOPI already exists (topi.image.affine_grid), only needs Relax op + legalization. Pairs with existinggrid_sample.
Tier 2 — Fills domain gaps and fixes broken paths
- [x]
resize3d— 3D volume resize for medical imaging (CT/MRI) and video. TOPI already exists (topi.image.resize3d), only needs Relax op + legalization. Note: ONNX frontend currently works around this by calling TOPI directly. - [x]
get_valid_counts— Score-based bounding box filtering. Filters out low-score boxes and returns valid count per batch. Current TOPI is a no-op stub; needs full implementation. - [x]
non_max_suppression(classic) — Flexible single-class NMS. Performs IoU-based suppression on filtered boxes from get_valid_counts. TOPI was removed; needs reimplementation. Complements existing all_class_non_max_suppression for custom post-processing pipelines. - [x]
multibox_transform_loc— Decodes bounding box predictions using anchor priors + predicted offsets, with score thresholding. Only needed by TFLite DETECTION_POSTPROCESS. No existing TOPI or Relax op; needs full implementation.
Tier 3 — Frontend integration
- [x] ONNX
RoiAlign: add relax.op.vision.roi_align op definition + legalization, implement converter class, uncomment registration, add tests - [x] ONNX
AffineGrid: add relax.op.image.affine_grid op definition + legalization, implement converter class, add tests - [x] ONNX
Resize 5-D: add relax.op.image.resize3d op definition + legalization, replace bb.emit_te workaround in converter with relax.op.image.resize3d, add tests - [x] ONNX
GridSample: implement converter class (relax op already exists), uncomment registration, add tests - [x] PyTorch
torchvision.ops.roi_align: register converter (depends on relax.op.vision.roi_align), add tests - [x] PyTorch
torch.nn.functional.affine_grid: register converter (depends on relax.op.image.affine_grid), add tests - [x] PyTorch
torch.nn.functional.interpolate3D mode: add 5-D branch in converter using relax.op.image.resize3d (depends on resize3d op), add tests - [x] TFLite
NON_MAX_SUPPRESSION_V5: verify/add get_valid_counts + non_max_suppression relax ops, implement converter, add tests - [x] TFLite
DETECTION_POSTPROCESS: implement converter (anchor decoding + NMS), depends on same relax ops as above, add tests
Implementation reference
- Existing vision op pattern:
src/relax/op/vision/nms.cc+python/tvm/relax/op/vision/nms.py - Existing image op pattern:
src/relax/op/image/resize.cc+python/tvm/relax/op/image/image.py - Legalization:
python/tvm/relax/transform/legalize_ops/vision.py,image.py roi_alignreference implementation for testing:python/tvm/topi/testing/roi_align_python.py- Historical Relay implementations as design reference (Relax has a different IR design, so these should not be copied directly):
v0.19.0tag
affine_grid and resize3d are good first issues — TOPI already exists, just follow the existing resize2d / grid_sample pattern. If you're interested in contributing, please comment below to claim a task before starting work.
Hi @tlopex, I'd like to take on resize3d.
Hi @tlopex, I’d like to claim affine_grid, including the Relax op + legalization and the PyTorch frontend integration for torch.nn.functional.affine_grid.
Hi @tlopex, I’d like to take on roi_align.
Hi @tlopex , I’d like to work on ONNX frontend integration for GridSample.
Hi @tlopex, I'd like to claim the ONNX frontend integration for Resize 5-D → resize3d. I'll start working on it now and open a draft PR in the meantime while @Dayuxiaoshui finishes the resize3d Relax op, so the two can land together.
@tlopex @nirdesh17 I apologize for the overlap. I saw that nirdesh17 had claimed GridSample, but I was excited to contribute and couldn't wait to dive in as a beginner. If nirdesh17 has already started working on it, I'm happy to close my PR and defer to them. Sorry about that!
@tlopex @nirdesh17 I apologize for the overlap. I saw that nirdesh17 had claimed GridSample, but I was excited to contribute and couldn't wait to dive in as a beginner. If nirdesh17 has already started working on it, I'm happy to close my PR and defer to them. Sorry about that!
@OmarAzizi No worries at all! I had just started exploring it and was still understanding things, so please go ahead with your PR. I’ll follow along and learn from it
Hi @tlopex, @Aharrypotter — I see affine_grid Relax op and PyTorch frontend are being worked on. I’d like to take up the ONNX frontend integration for affine_grid once the backend is ready. Please let me know if that’s okay.
Hi @nirdesh17, thanks for your interest! The ONNX frontend integration for AffineGrid is actually already included in my PR #18933 — it covers the full Relax op + legalization + PyTorch frontend + ONNX frontend (opset 20) as a single package.
If you're looking for other tasks to pick up, there are still several unclaimed items on this issue:
- PyTorch
interpolate3D mode (Tier 3) — depends on resize3d (#18931), frontend converter needed
Happy to help if you have questions about any of these!
Hi @tlopex, I'd like to claim get_valid_counts + non_max_suppression (classic) (Tier 2). I'll start with the TOPI implementation for both, then build up the Relax op registration, legalization, and tests.
Hi @tlopex, I’d like to work on the PyTorch interpolate 3D mode frontend integration. If no one is currently working on it, I’ll start once the resize3d backend is ready.
Hi @tlopex, I'd like to claim multibox_transform_loc (Tier 2): implement TOPI + Relax op + legalization, then wire it from the TFLite frontend for DETECTION_POSTPROCESS as a follow-up or in the same series of PRs as appropriate.
Hi @LudovicoYIN and @tlopex. I'm interested in contributing to the roi_align pipeline and wanted to check in.
@LudovicoYIN, does your current scope include the Tier 3 frontend integrations (ONNX RoiAlign + PyTorch torchvision.ops.roi_align), or are those still open? I'm happy to take those off your plate if you're focused on the Tier 1 stack.
That said, I'm also open to helping with any part of the Tier 1 work (TOPI + Relax op + legalization) if there's room to collaborate there too. Just want to make sure we're not duplicating effort. Let me know what makes sense!
Hi @OmarAzizi , thanks for checking. I’m already working on roi_align and my current scope includes the frontend integration as well, specifically:
- ONNX RoiAlign
- PyTorch torchvision.ops.roi_align
The work is currently in the final polishing / validation stage.
@LudovicoYIN Alright, thank you for letting me know
@Aharrypotter, you've taken on quite a broad scope. affine_grid (full stack + ONNX + PyTorch frontend) and get_valid_counts + non_max_suppression (Tier 2). That's a lot of ground to cover in parallel.
I'd love to contribute and wanted to check if there are any parts of your claimed work you'd be open to delegating, or that you haven't started yet, where a second contributor could help? For example:
- The TFLite NON_MAX_SUPPRESSION_V5 frontend (Tier 3). This depends on the get_valid_counts + NMS Relax ops you're building, so it can't start until those land, but I could pick it up as a follow-on once the ops are ready.
- Any part of the get_valid_counts + NMS Tier 2 stack if you'd prefer to split the work.
@Aharrypotter, you've taken on quite a broad scope. affine_grid (full stack + ONNX + PyTorch frontend) and get_valid_counts + non_max_suppression (Tier 2). That's a lot of ground to cover in parallel.
I'd love to contribute and wanted to check if there are any parts of your claimed work you'd be open to delegating, or that you haven't started yet, where a second contributor could help? For example:
- The TFLite NON_MAX_SUPPRESSION_V5 frontend (Tier 3). This depends on the get_valid_counts + NMS Relax ops you're building, so it can't start until those land, but I could pick it up as a follow-on once the ops are ready.
- Any part of the get_valid_counts + NMS Tier 2 stack if you'd prefer to split the work.
Sorry for the delayed response—things have been pretty busy on my end lately! Thanks for the offer to help! That sounds like a great plan.
I'll keep the affine_grid work and the Tier 2 get_valid_counts + NMS stack. Feel free to take ownership of the TFLite NON_MAX_SUPPRESSION_V5 frontend (Tier 3).
I'll give you a heads-up as soon as the Tier 2 ops are merged so you can get started on the Tier 3 follow-on. Thanks again!
@Aharrypotter, you've taken on quite a broad scope. affine_grid (full stack + ONNX + PyTorch frontend) and get_valid_counts + non_max_suppression (Tier 2). That's a lot of ground to cover in parallel. I'd love to contribute and wanted to check if there are any parts of your claimed work you'd be open to delegating, or that you haven't started yet, where a second contributor could help? For example:
- The TFLite NON_MAX_SUPPRESSION_V5 frontend (Tier 3). This depends on the get_valid_counts + NMS Relax ops you're building, so it can't start until those land, but I could pick it up as a follow-on once the ops are ready.
- Any part of the get_valid_counts + NMS Tier 2 stack if you'd prefer to split the work.
Sorry for the delayed response—things have been pretty busy on my end lately! Thanks for the offer to help! That sounds like a great plan.
I'll keep the affine_grid work and the Tier 2
get_valid_counts+NMSstack. Feel free to take ownership of the TFLiteNON_MAX_SUPPRESSION_V5frontend (Tier 3).I'll give you a heads-up as soon as the Tier 2 ops are merged so you can get started on the Tier 3 follow-on. Thanks again!
Sounds good, thank you
Hey @OmarAzizi, good news! PR #18943 with the Tier 2 ops is now merged.
The runway is all yours for the Tier 3 TFLite frontend work. Feel free to ping me if you have any questions about the Relax/TOPI implementation. Looking forward to your PR!
Hey @OmarAzizi, just checking in on the Tier 3 ops! Are you currently working on NON_MAX_SUPPRESSION_V5 and DETECTION_POSTPROCESS?
If you haven't started on these two yet, I'd be happy to take them. Let me know if you're already on it, otherwise I can pick them up!