From ac034fd4e6024b0a5e02fa416b21406934e075eb Mon Sep 17 00:00:00 2001 From: "A. Unique TensorFlower" Date: Wed, 5 Jun 2019 14:02:34 -0700 Subject: [PATCH] Special case 1D resizes and no-op resizes. Bilinear resize from [X, Y] -> [X, Y] is a no-op, but previously, ResizeBilinear would generated a 1x1 convolution. Bilinear resize from [X, A] -> [X, B] or [A, Y] -> [B, Y] are one dimensional, but previously the code used the two dimensional general case if the kernel size was sufficiently small. PiperOrigin-RevId: 251713592 --- tensorflow/compiler/tests/image_ops_test.py | 2 ++ tensorflow/compiler/tf2xla/kernels/image_resize_ops.cc | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/tensorflow/compiler/tests/image_ops_test.py b/tensorflow/compiler/tests/image_ops_test.py index 34e2c8c8986..28a1dd9ebdb 100644 --- a/tensorflow/compiler/tests/image_ops_test.py +++ b/tensorflow/compiler/tests/image_ops_test.py @@ -560,6 +560,8 @@ class ResizeBilinearTest(parameterized.TestCase, xla_test.XLATestCase): ("72x72To456x456", 72, 72, 456, 456), ("86x86To456x456", 86, 86, 456, 456), ("100x100To456x456", 100, 100, 456, 456), + ("64x64To224x224", 64, 64, 224, 224), + ("224x224To224x224", 224, 224, 224, 224), # This test is disabled because it is very slow. It is slow because # 383 is prime, 383 and 2047 are coprime, and 2048 is large. # ("Disabled_384x72To2048x384", 384, 72, 2048, 384), diff --git a/tensorflow/compiler/tf2xla/kernels/image_resize_ops.cc b/tensorflow/compiler/tf2xla/kernels/image_resize_ops.cc index 9ee17d1aa9c..aaa322eef87 100644 --- a/tensorflow/compiler/tf2xla/kernels/image_resize_ops.cc +++ b/tensorflow/compiler/tf2xla/kernels/image_resize_ops.cc @@ -312,8 +312,11 @@ xla::XlaOp ResizeUsingDilationAndConvolution( } // Split convolutions into independent dimensions if they would be a very - // large kernel. - if (dims.kernel_size[0] * dims.kernel_size[1] < kMax2DKernelSize) { + // large kernel or if one or more of the dimensions are already equal. + bool decompose_resize = + in_size[0] == out_size[0] || in_size[1] == out_size[1] || + dims.kernel_size[0] * dims.kernel_size[1] >= kMax2DKernelSize; + if (!decompose_resize) { xla::XlaOp kernel = MakeGeneralResizeKernel(builder, type, dims.kernel_size, channels, is_kernel_bilinear); output =