Skip to content

Commit

Permalink
Support tf ResizeArea op. (onnx#2241)
Browse files Browse the repository at this point in the history
* Support ResizeArea op.

Signed-off-by: Jay Zhang <jiz@microsoft.com>

---------

Signed-off-by: Jay Zhang <jiz@microsoft.com>
Signed-off-by: Me <me@example.com>
  • Loading branch information
fatcat-z authored and Me committed Oct 12, 2023
1 parent 586294b commit 27aed6d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions support_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@
| Relu | 1 ~ 18 |
| Relu6 | 1 ~ 18 |
| Reshape | 1 ~ 18 |
| ResizeArea | 7 ~ 18 |
| ResizeBicubic | 7 ~ 18 |
| ResizeBilinear | 7 ~ 18 |
| ResizeNearestNeighbor | 7 ~ 18 |
Expand Down
27 changes: 27 additions & 0 deletions tests/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
quantize_and_dequantize = tf.quantization.quantize_and_dequantize
resize_bilinear = tf.compat.v1.image.resize_bilinear
resize_bilinear_v2 = tf.compat.v2.image.resize
resize_area = tf.compat.v1.image.resize_area
is_nan = tf.math.is_nan
is_inf = tf.math.is_inf
floormod = tf.math.floormod
Expand All @@ -84,6 +85,7 @@
fused_batch_norm = tf.compat.v1.nn.fused_batch_norm
dropout = tf.compat.v1.nn.dropout
quantize_and_dequantize = tf.compat.v1.quantization.quantize_and_dequantize
resize_area = tf.compat.v1.image.resize_area
resize_nearest_neighbor = tf.compat.v1.image.resize_nearest_neighbor
resize_bilinear = tf.compat.v1.image.resize_bilinear
if Version(tf.__version__) >= Version("1.14"):
Expand Down Expand Up @@ -3285,6 +3287,31 @@ def func(x, x_new_size_):
return tf.identity(x_, name=_TFOUTPUT)
self._run_test_case(func, [_OUTPUT], {_INPUT: x_val, _INPUT1: x_new_size})

@skip_caffe2_backend()
def test_resize_area(self):
x_shape = [1, 15, 20, 2]
x_new_size = [30, 40]
x_val = np.arange(1, 1 + np.prod(x_shape)).astype("float32").reshape(x_shape)
def func(x):
x_new_size_ = tf.constant(x_new_size)
x_ = resize_area(x, x_new_size_)
return tf.identity(x_, name=_TFOUTPUT)
_ = self._run_test_case(func, [_OUTPUT], {_INPUT: x_val})

# https://github.com/microsoft/onnxruntime/issues/17564
@skip_onnxruntime_backend("Blocked by onnxruntime issue #17564")
@skip_caffe2_backend()
def test_resize_area_align_coreners(self):
x_shape = [1, 15, 20, 2]
x_new_size = [30, 40]
x_val = np.arange(1, 1 + np.prod(x_shape)).astype("float32").reshape(x_shape)
def func(x):
x_new_size_ = tf.constant(x_new_size)
x_ = resize_area(x, x_new_size_, align_corners=True)
return tf.identity(x_, name=_TFOUTPUT)
_ = self._run_test_case(func, [_OUTPUT], {_INPUT: x_val})


@skip_caffe2_backend()
@check_opset_min_version(7, "resize_bilinear")
def test_resize_bilinear(self):
Expand Down
2 changes: 1 addition & 1 deletion tf2onnx/onnx_opset/nn.py
Original file line number Diff line number Diff line change
Expand Up @@ -1352,7 +1352,7 @@ def version_13(cls, ctx, node, **kwargs):
cls.any_version_after11(13, ctx, node, **kwargs)


@tf_op(["ResizeBilinear", "ResizeNearestNeighbor", "ResizeBicubic"])
@tf_op(["ResizeBilinear", "ResizeNearestNeighbor", "ResizeBicubic", "ResizeArea"])
class Resize:
@classmethod
def version_7(cls, ctx, node, **kwargs):
Expand Down

0 comments on commit 27aed6d

Please sign in to comment.