Skip to content

Commit b57fe91

Browse files
authored
Support tf ResizeArea op. (#2241)
* Support ResizeArea op. Signed-off-by: Jay Zhang <[email protected]> --------- Signed-off-by: Jay Zhang <[email protected]>
1 parent d5b7f39 commit b57fe91

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

support_status.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@
181181
| Relu | 1 ~ 18 |
182182
| Relu6 | 1 ~ 18 |
183183
| Reshape | 1 ~ 18 |
184+
| ResizeArea | 7 ~ 18 |
184185
| ResizeBicubic | 7 ~ 18 |
185186
| ResizeBilinear | 7 ~ 18 |
186187
| ResizeNearestNeighbor | 7 ~ 18 |

tests/test_backend.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
quantize_and_dequantize = tf.quantization.quantize_and_dequantize
6767
resize_bilinear = tf.compat.v1.image.resize_bilinear
6868
resize_bilinear_v2 = tf.compat.v2.image.resize
69+
resize_area = tf.compat.v1.image.resize_area
6970
is_nan = tf.math.is_nan
7071
is_inf = tf.math.is_inf
7172
floormod = tf.math.floormod
@@ -84,6 +85,7 @@
8485
fused_batch_norm = tf.compat.v1.nn.fused_batch_norm
8586
dropout = tf.compat.v1.nn.dropout
8687
quantize_and_dequantize = tf.compat.v1.quantization.quantize_and_dequantize
88+
resize_area = tf.compat.v1.image.resize_area
8789
resize_nearest_neighbor = tf.compat.v1.image.resize_nearest_neighbor
8890
resize_bilinear = tf.compat.v1.image.resize_bilinear
8991
if Version(tf.__version__) >= Version("1.14"):
@@ -3285,6 +3287,31 @@ def func(x, x_new_size_):
32853287
return tf.identity(x_, name=_TFOUTPUT)
32863288
self._run_test_case(func, [_OUTPUT], {_INPUT: x_val, _INPUT1: x_new_size})
32873289

3290+
@skip_caffe2_backend()
3291+
def test_resize_area(self):
3292+
x_shape = [1, 15, 20, 2]
3293+
x_new_size = [30, 40]
3294+
x_val = np.arange(1, 1 + np.prod(x_shape)).astype("float32").reshape(x_shape)
3295+
def func(x):
3296+
x_new_size_ = tf.constant(x_new_size)
3297+
x_ = resize_area(x, x_new_size_)
3298+
return tf.identity(x_, name=_TFOUTPUT)
3299+
_ = self._run_test_case(func, [_OUTPUT], {_INPUT: x_val})
3300+
3301+
# https://github.com/microsoft/onnxruntime/issues/17564
3302+
@skip_onnxruntime_backend("Blocked by onnxruntime issue #17564")
3303+
@skip_caffe2_backend()
3304+
def test_resize_area_align_coreners(self):
3305+
x_shape = [1, 15, 20, 2]
3306+
x_new_size = [30, 40]
3307+
x_val = np.arange(1, 1 + np.prod(x_shape)).astype("float32").reshape(x_shape)
3308+
def func(x):
3309+
x_new_size_ = tf.constant(x_new_size)
3310+
x_ = resize_area(x, x_new_size_, align_corners=True)
3311+
return tf.identity(x_, name=_TFOUTPUT)
3312+
_ = self._run_test_case(func, [_OUTPUT], {_INPUT: x_val})
3313+
3314+
32883315
@skip_caffe2_backend()
32893316
@check_opset_min_version(7, "resize_bilinear")
32903317
def test_resize_bilinear(self):

tf2onnx/onnx_opset/nn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1352,7 +1352,7 @@ def version_13(cls, ctx, node, **kwargs):
13521352
cls.any_version_after11(13, ctx, node, **kwargs)
13531353

13541354

1355-
@tf_op(["ResizeBilinear", "ResizeNearestNeighbor", "ResizeBicubic"])
1355+
@tf_op(["ResizeBilinear", "ResizeNearestNeighbor", "ResizeBicubic", "ResizeArea"])
13561356
class Resize:
13571357
@classmethod
13581358
def version_7(cls, ctx, node, **kwargs):

0 commit comments

Comments
 (0)