tlopex commented on code in PR #18963:
URL: https://github.com/apache/tvm/pull/18963#discussion_r3021129119


##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -2632,6 +2632,91 @@ def _impl_v1(cls, bb, inputs, attr, params):
         return inputs[0]
 
 
+def _onnx_resize_spatial_roi_vector(roi_full: relax.Expr, rank: int) -> 
relax.Expr:
+    """Map ONNX ROI [starts..., ends...] to TOPI spatial ROI (drop N/C 
axes)."""
+    return relax.op.concat(
+        [
+            relax.op.strided_slice(roi_full, axes=[0], begin=[2], end=[rank]),
+            relax.op.strided_slice(roi_full, axes=[0], begin=[rank + 2], 
end=[2 * rank]),
+        ],
+        axis=0,
+    )
+
+
+def _emit_resize_topi_dynamic_roi(
+    bb: relax.BlockBuilder,
+    data: relax.Expr,
+    roi_spatial_vec: relax.Expr,
+    sizes_spatial: list,
+    rank: int,
+    topi_mode: str,
+    coord_mode: str,
+    rounding_method: str,
+    cubic_coeff_a: float,
+    exclude_outside: int,
+    extrapolation_value: float,
+) -> relax.Expr:
+    """Lower Resize with runtime ROI via TOPI, which supports Expr ROI."""
+    if rank == 3:
+
+        def resize1d_dyn(d, r, s0):
+            return topi.image.resize1d(
+                d,
+                (r[0], r[1]),
+                [s0],
+                "NCW",
+                topi_mode,
+                coord_mode,
+                rounding_method,
+                cubic_coeff_a,
+                exclude_outside,
+                extrapolation_value,
+            )
+
+        return bb.emit_te(resize1d_dyn, data, roi_spatial_vec, 
sizes_spatial[0])
+
+    if rank == 4:
+
+        def resize2d_dyn(d, r, s0, s1):
+            return topi.image.resize2d(
+                d,
+                (r[0], r[1], r[2], r[3]),
+                (s0, s1),
+                layout="NCHW",
+                method=topi_mode,
+                coordinate_transformation_mode=coord_mode,
+                rounding_method=rounding_method,
+                bicubic_alpha=cubic_coeff_a,
+                bicubic_exclude=exclude_outside,
+                extrapolation_value=extrapolation_value,
+            )
+
+        return bb.emit_te(resize2d_dyn, data, roi_spatial_vec, 
sizes_spatial[0], sizes_spatial[1])
+
+    def resize3d_dyn(d, r, s0, s1, s2):
+        return topi.image.resize3d(
+            d,
+            (r[0], r[1], r[2], r[3], r[4], r[5]),

Review Comment:
   This makes sense



##########
python/tvm/relax/frontend/onnx/onnx_frontend.py:
##########
@@ -2706,11 +2794,26 @@ def _impl_v18(cls, bb, inputs, attr, params):
             else:
                 assert f"Type {type(sizes)} for size is currently unsupported."

Review Comment:
   This makes sense as well



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to