• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7     http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 // TODO(shlens, sherrym): Consider adding additional tests in image_ops.py in
17 // order to compare the reference implementation for image resizing in Python
18 // Image Library.
19 #include "tensorflow/core/common_runtime/device_factory.h"
20 #include "tensorflow/core/framework/allocator.h"
21 #include "tensorflow/core/framework/fake_input.h"
22 #include "tensorflow/core/framework/node_def_builder.h"
23 #include "tensorflow/core/framework/op_kernel.h"
24 #include "tensorflow/core/framework/tensor.h"
25 #include "tensorflow/core/framework/tensor_testutil.h"
26 #include "tensorflow/core/framework/types.h"
27 #include "tensorflow/core/framework/types.pb.h"
28 #include "tensorflow/core/kernels/ops_testutil.h"
29 #include "tensorflow/core/kernels/ops_util.h"
30 #include "tensorflow/core/lib/core/status_test_util.h"
31 #include "tensorflow/core/platform/test.h"
32 
33 namespace tensorflow {
34 enum class TestDevice { kCPU, kGPU };
35 
36 class ResizeNearestNeighborOpTestBase
37     : public OpsTestBase,
38       public ::testing::WithParamInterface<TestDevice> {
39  protected:
ResizeNearestNeighborOpTestBase(bool half_pixel_centers)40   explicit ResizeNearestNeighborOpTestBase(bool half_pixel_centers)
41       : align_corners_(false), half_pixel_centers_(half_pixel_centers) {}
SetUp()42   void SetUp() override {
43     if (GetParam() == TestDevice::kGPU) {
44       std::unique_ptr<Device> device_gpu(
45           DeviceFactory::NewDevice(/*type=*/"GPU", /*options=*/{},
46                                    /*name_prefix=*/"/job:a/replica:0/task:0"));
47       SetDevice(DEVICE_GPU, std::move(device_gpu));
48     }
49 
50     TF_EXPECT_OK(NodeDefBuilder("resize_nn_op", "ResizeNearestNeighbor")
51                      .Input(FakeInput(DT_FLOAT))
52                      .Input(FakeInput(DT_INT32))
53                      .Attr("align_corners", align_corners_)
54                      .Attr("half_pixel_centers", half_pixel_centers_)
55                      .Finalize(node_def()));
56     TF_EXPECT_OK(InitOp());
57   }
58   bool align_corners_;
59   bool half_pixel_centers_;
60 };
61 
62 class ResizeNearestNeighborOpTest : public ResizeNearestNeighborOpTestBase {
63  protected:
ResizeNearestNeighborOpTest()64   ResizeNearestNeighborOpTest() : ResizeNearestNeighborOpTestBase(false) {}
65 };
66 
67 class ResizeNearestNeighborHalfPixelCentersOpTest
68     : public ResizeNearestNeighborOpTestBase {
69  protected:
ResizeNearestNeighborHalfPixelCentersOpTest()70   ResizeNearestNeighborHalfPixelCentersOpTest()
71       : ResizeNearestNeighborOpTestBase(true) {}
72 };
73 
74 // TODO(jflynn): Add some actual tests for the half pixel centers case.
75 
76 class ResizeNearestNeighborOpAlignCornersTest
77     : public OpsTestBase,
78       public ::testing::WithParamInterface<TestDevice> {
79  protected:
ResizeNearestNeighborOpAlignCornersTest()80   ResizeNearestNeighborOpAlignCornersTest() : align_corners_(true) {}
SetUp()81   void SetUp() override {
82     if (GetParam() == TestDevice::kGPU) {
83       std::unique_ptr<Device> device_gpu(
84           DeviceFactory::NewDevice(/*type=*/"GPU", /*options=*/{},
85                                    /*name_prefix=*/"/job:a/replica:0/task:0"));
86       SetDevice(DEVICE_GPU, std::move(device_gpu));
87     }
88 
89     TF_EXPECT_OK(NodeDefBuilder("resize_nn_op", "ResizeNearestNeighbor")
90                      .Input(FakeInput(DT_FLOAT))
91                      .Input(FakeInput(DT_INT32))
92                      .Attr("align_corners", align_corners_)
93                      .Finalize(node_def()));
94     TF_EXPECT_OK(InitOp());
95   }
96   bool align_corners_;
97 };
98 
TEST_P(ResizeNearestNeighborOpTest,TestNearest2x2To1x1)99 TEST_P(ResizeNearestNeighborOpTest, TestNearest2x2To1x1) {
100   // Input:
101   //  1, 2
102   //  3, 4
103   AddInputFromArray<float>(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4});
104   AddInputFromArray<int32>(TensorShape({2}), {1, 1});
105   TF_ASSERT_OK(RunOpKernel());
106 
107   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 1, 1, 1}));
108 
109   // clang-format off
110   test::FillValues<float>(&expected, {1});
111 
112   // clang-format on
113   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
114 }
115 
TEST_P(ResizeNearestNeighborOpAlignCornersTest,TestNearest2x2AlignCornersTo1x1)116 TEST_P(ResizeNearestNeighborOpAlignCornersTest,
117        TestNearest2x2AlignCornersTo1x1) {
118   // Input:
119   //  1, 2
120   //  3, 4
121   AddInputFromArray<float>(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4});
122   AddInputFromArray<int32>(TensorShape({2}), {1, 1});
123   TF_ASSERT_OK(RunOpKernel());
124 
125   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 1, 1, 1}));
126 
127   // clang-format off
128   test::FillValues<float>(&expected, {1});
129 
130   // clang-format on
131   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
132 }
133 
TEST_P(ResizeNearestNeighborOpTest,TestNearest2x2To3x3)134 TEST_P(ResizeNearestNeighborOpTest, TestNearest2x2To3x3) {
135   // Input:
136   //  1, 2
137   //  3, 4
138   AddInputFromArray<float>(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4});
139   AddInputFromArray<int32>(TensorShape({2}), {3, 3});
140   TF_ASSERT_OK(RunOpKernel());
141 
142   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 3, 3, 1}));
143 
144   // clang-format off
145   test::FillValues<float>(&expected,
146     {1, 1, 2,
147      1, 1, 2,
148      3, 3, 4});
149 
150   // clang-format on
151   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
152 }
153 
TEST_P(ResizeNearestNeighborOpAlignCornersTest,TestNearestAlignCorners2x2To3x3)154 TEST_P(ResizeNearestNeighborOpAlignCornersTest,
155        TestNearestAlignCorners2x2To3x3) {
156   // Input:
157   //  1, 2
158   //  3, 4
159   AddInputFromArray<float>(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4});
160   AddInputFromArray<int32>(TensorShape({2}), {3, 3});
161   TF_ASSERT_OK(RunOpKernel());
162 
163   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 3, 3, 1}));
164 
165   // clang-format off
166   test::FillValues<float>(&expected,
167     {1, 2, 2,
168      3, 4, 4,
169      3, 4, 4});
170 
171   // clang-format on
172   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
173 }
174 
TEST_P(ResizeNearestNeighborOpTest,TestNearest3x3To2x2)175 TEST_P(ResizeNearestNeighborOpTest, TestNearest3x3To2x2) {
176   // Input:
177   //  1, 2, 3
178   //  4, 5, 6
179   //  7, 8, 9
180   AddInputFromArray<float>(TensorShape({1, 3, 3, 1}),
181                            {1, 2, 3, 4, 5, 6, 7, 8, 9});
182   AddInputFromArray<int32>(TensorShape({2}), {2, 2});
183   TF_ASSERT_OK(RunOpKernel());
184 
185   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 2, 2, 1}));
186 
187   // clang-format off
188   test::FillValues<float>(&expected,
189     {1, 2,
190      4, 5});
191 
192   // clang-format on
193   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
194 }
195 
TEST_P(ResizeNearestNeighborOpAlignCornersTest,TestNearestAlignCorners3x3To2x2)196 TEST_P(ResizeNearestNeighborOpAlignCornersTest,
197        TestNearestAlignCorners3x3To2x2) {
198   // Input:
199   //  1, 2, 3
200   //  4, 5, 6
201   //  7, 8, 9
202   AddInputFromArray<float>(TensorShape({1, 3, 3, 1}),
203                            {1, 2, 3, 4, 5, 6, 7, 8, 9});
204   AddInputFromArray<int32>(TensorShape({2}), {2, 2});
205   TF_ASSERT_OK(RunOpKernel());
206 
207   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 2, 2, 1}));
208 
209   // clang-format off
210   test::FillValues<float>(&expected,
211     {1, 3,
212      7, 9});
213 
214   // clang-format on
215   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
216 }
217 
TEST_P(ResizeNearestNeighborOpTest,TestNearest2x2To2x5)218 TEST_P(ResizeNearestNeighborOpTest, TestNearest2x2To2x5) {
219   // Input:
220   //  1, 2
221   //  3, 4
222   AddInputFromArray<float>(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4});
223   AddInputFromArray<int32>(TensorShape({2}), {2, 5});
224   TF_ASSERT_OK(RunOpKernel());
225 
226   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 2, 5, 1}));
227 
228   // clang-format off
229   test::FillValues<float>(&expected,
230     {1, 1, 1, 2, 2,
231      3, 3, 3, 4, 4});
232 
233   // clang-format on
234   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
235 }
236 
TEST_P(ResizeNearestNeighborOpTest,TestNearestNeighbor4x4To3x3)237 TEST_P(ResizeNearestNeighborOpTest, TestNearestNeighbor4x4To3x3) {
238   // Input:
239   //  1,  2,  3,  4
240   //  5,  6,  7,  8
241   //  9, 10, 11, 12
242   // 13, 14, 15, 16
243   AddInputFromArray<float>(
244       TensorShape({1, 4, 4, 1}),
245       {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16});
246   AddInputFromArray<int32>(TensorShape({2}), {3, 3});
247   TF_ASSERT_OK(RunOpKernel());
248 
249   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 3, 3, 1}));
250 
251   // clang-format off
252   test::FillValues<float>(&expected,
253     {1,  2,  3,
254      5,  6,  7,
255      9, 10, 11});
256 
257   // clang-format on
258   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
259 }
260 
TEST_P(ResizeNearestNeighborOpAlignCornersTest,TestNearestNeighborAlignCorners4x4To3x3)261 TEST_P(ResizeNearestNeighborOpAlignCornersTest,
262        TestNearestNeighborAlignCorners4x4To3x3) {
263   // Input:
264   //  1,  2,  3,  4
265   //  5,  6,  7,  8
266   //  9, 10, 11, 12
267   // 13, 14, 15, 16
268   AddInputFromArray<float>(
269       TensorShape({1, 4, 4, 1}),
270       {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16});
271   AddInputFromArray<int32>(TensorShape({2}), {3, 3});
272   TF_ASSERT_OK(RunOpKernel());
273 
274   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 3, 3, 1}));
275 
276   // clang-format off
277   test::FillValues<float>(&expected,
278     { 1,  3,  4,
279       9, 11, 12,
280      13, 15, 16});
281 
282   // clang-format on
283   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
284 }
285 
TEST_P(ResizeNearestNeighborOpTest,TestNearest2x2To5x2)286 TEST_P(ResizeNearestNeighborOpTest, TestNearest2x2To5x2) {
287   // Input:
288   //  1, 2
289   //  3, 4
290   AddInputFromArray<float>(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4});
291   AddInputFromArray<int32>(TensorShape({2}), {5, 2});
292   TF_ASSERT_OK(RunOpKernel());
293 
294   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 5, 2, 1}));
295 
296   // clang-format off
297   test::FillValues<float>(&expected,
298     {1, 2,
299      1, 2,
300      1, 2,
301      3, 4,
302      3, 4});
303 
304   // clang-format on
305   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
306 }
307 
TEST_P(ResizeNearestNeighborOpTest,TestNearest2x2To4x4)308 TEST_P(ResizeNearestNeighborOpTest, TestNearest2x2To4x4) {
309   // Input:
310   //  1, 2
311   //  3, 4
312   AddInputFromArray<float>(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4});
313   AddInputFromArray<int32>(TensorShape({2}), {4, 4});
314   TF_ASSERT_OK(RunOpKernel());
315 
316   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 4, 4, 1}));
317 
318   // clang-format off
319   test::FillValues<float>(&expected,
320     {1, 1, 2, 2,
321      1, 1, 2, 2,
322      3, 3, 4, 4,
323      3, 3, 4, 4});
324 
325   // clang-format on
326   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
327 }
328 
TEST_P(ResizeNearestNeighborOpTest,TestNearest2x2x2x2To2x3x3x2)329 TEST_P(ResizeNearestNeighborOpTest, TestNearest2x2x2x2To2x3x3x2) {
330   // Input:
331   //  [ [ 1, 1 ], [ 2, 2],
332   //    [ 3, 3 ], [ 4, 4] ],
333   //  [ [ 5, 5 ], [ 6, 6],
334   //    [ 7, 7 ], [ 8, 8] ]
335   AddInputFromArray<float>(TensorShape({2, 2, 2, 2}),
336                            {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8});
337   AddInputFromArray<int32>(TensorShape({2}), {3, 3});
338   TF_ASSERT_OK(RunOpKernel());
339 
340   Tensor expected(allocator(), DT_FLOAT, TensorShape({2, 3, 3, 2}));
341 
342   // clang-format off
343   test::FillValues<float>(&expected,
344     {1, 1, 1,
345      1, 2, 2,
346      1, 1, 1,
347      1, 2, 2,
348      3, 3, 3,
349      3, 4, 4,
350      5, 5, 5,
351      5, 6, 6,
352      5, 5, 5,
353      5, 6, 6,
354      7, 7, 7,
355      7, 8, 8});
356 
357   // clang-format on
358   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
359 }
360 
TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest,TestNearest5x2To2x2)361 TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest, TestNearest5x2To2x2) {
362   // Input:
363   //  1, 2
364   //  3, 4
365   AddInputFromArray<float>(TensorShape({1, 2, 5, 1}),
366                            {1, 2, 3, 4, 5, 1, 2, 3, 4, 5});
367   AddInputFromArray<int32>(TensorShape({2}), {2, 2});
368   TF_ASSERT_OK(RunOpKernel());
369 
370   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 2, 2, 1}));
371 
372   // clang-format off
373   test::FillValues<float>(&expected, {2, 4, 2, 4});
374 
375   // clang-format on
376   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
377 }
378 
TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest,TestNearest2x2To1x1)379 TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest, TestNearest2x2To1x1) {
380   // Input:
381   //  1, 2
382   //  3, 4
383   AddInputFromArray<float>(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4});
384   AddInputFromArray<int32>(TensorShape({2}), {1, 1});
385   TF_ASSERT_OK(RunOpKernel());
386 
387   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 1, 1, 1}));
388 
389   // clang-format off
390   test::FillValues<float>(&expected, {4});
391 
392   // clang-format on
393   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
394 }
395 
TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest,TestNearest2x2To3x3)396 TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest, TestNearest2x2To3x3) {
397   // Input:
398   //  1, 2
399   //  3, 4
400   AddInputFromArray<float>(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4});
401   AddInputFromArray<int32>(TensorShape({2}), {3, 3});
402   TF_ASSERT_OK(RunOpKernel());
403 
404   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 3, 3, 1}));
405 
406   // clang-format off
407   test::FillValues<float>(&expected,
408     {1, 2, 2,
409      3, 4, 4,
410      3, 4, 4});
411 
412   // clang-format on
413   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
414 }
415 
TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest,TestNearest3x3To2x2)416 TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest, TestNearest3x3To2x2) {
417   // Input:
418   //  1, 2, 3
419   //  4, 5, 6
420   //  7, 8, 9
421   AddInputFromArray<float>(TensorShape({1, 3, 3, 1}),
422                            {1, 2, 3, 4, 5, 6, 7, 8, 9});
423   AddInputFromArray<int32>(TensorShape({2}), {2, 2});
424   TF_ASSERT_OK(RunOpKernel());
425 
426   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 2, 2, 1}));
427 
428   // clang-format off
429   test::FillValues<float>(&expected,
430     {1, 3,
431      7, 9});
432 
433   // clang-format on
434   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
435 }
436 
TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest,TestNearest2x2To2x5)437 TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest, TestNearest2x2To2x5) {
438   // Input:
439   //  1, 2
440   //  3, 4
441   AddInputFromArray<float>(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4});
442   AddInputFromArray<int32>(TensorShape({2}), {2, 5});
443   TF_ASSERT_OK(RunOpKernel());
444 
445   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 2, 5, 1}));
446 
447   // clang-format off
448   test::FillValues<float>(&expected,
449     {1, 1, 2, 2, 2,
450      3, 3, 4, 4, 4});
451 
452   // clang-format on
453   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
454 }
455 
TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest,TestNearestNeighbor4x4To3x3)456 TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest,
457        TestNearestNeighbor4x4To3x3) {
458   // Input:
459   //  1,  2,  3,  4
460   //  5,  6,  7,  8
461   //  9, 10, 11, 12
462   // 13, 14, 15, 16
463   AddInputFromArray<float>(
464       TensorShape({1, 4, 4, 1}),
465       {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16});
466   AddInputFromArray<int32>(TensorShape({2}), {3, 3});
467   TF_ASSERT_OK(RunOpKernel());
468 
469   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 3, 3, 1}));
470 
471   // clang-format off
472   test::FillValues<float>(&expected,
473     {1,  3,  4,
474      9, 11, 12,
475      13, 15, 16});
476 
477   // clang-format on
478   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
479 }
480 
TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest,TestNearest2x2To5x2)481 TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest, TestNearest2x2To5x2) {
482   // Input:
483   //  1, 2
484   //  3, 4
485   AddInputFromArray<float>(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4});
486   AddInputFromArray<int32>(TensorShape({2}), {5, 2});
487   TF_ASSERT_OK(RunOpKernel());
488 
489   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 5, 2, 1}));
490 
491   // clang-format off
492   test::FillValues<float>(&expected,
493     {1, 2,
494      1, 2,
495      3, 4,
496      3, 4,
497      3, 4});
498 
499   // clang-format on
500   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
501 }
502 
TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest,TestNearest2x2To4x4)503 TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest, TestNearest2x2To4x4) {
504   // Input:
505   //  1, 2
506   //  3, 4
507   AddInputFromArray<float>(TensorShape({1, 2, 2, 1}), {1, 2, 3, 4});
508   AddInputFromArray<int32>(TensorShape({2}), {4, 4});
509   TF_ASSERT_OK(RunOpKernel());
510 
511   Tensor expected(allocator(), DT_FLOAT, TensorShape({1, 4, 4, 1}));
512 
513   // clang-format off
514   test::FillValues<float>(&expected,
515     {1, 1, 2, 2,
516      1, 1, 2, 2,
517      3, 3, 4, 4,
518      3, 3, 4, 4});
519 
520   // clang-format on
521   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
522 }
523 
TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest,TestNearest2x2x2x2To2x3x3x2)524 TEST_P(ResizeNearestNeighborHalfPixelCentersOpTest,
525        TestNearest2x2x2x2To2x3x3x2) {
526   // Input:
527   //  [ [ 1, 1 ], [ 2, 2],
528   //    [ 3, 3 ], [ 4, 4] ],
529   //  [ [ 5, 5 ], [ 6, 6],
530   //    [ 7, 7 ], [ 8, 8] ]
531   AddInputFromArray<float>(TensorShape({2, 2, 2, 2}),
532                            {1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8});
533   AddInputFromArray<int32>(TensorShape({2}), {3, 3});
534   TF_ASSERT_OK(RunOpKernel());
535 
536   Tensor expected(allocator(), DT_FLOAT, TensorShape({2, 3, 3, 2}));
537 
538   // clang-format off
539   test::FillValues<float>(&expected,
540     {1, 1, 2, 2, 2, 2,
541      3, 3, 4, 4, 4, 4,
542      3, 3, 4, 4, 4, 4,
543      5, 5, 6, 6, 6, 6,
544      7, 7, 8, 8, 8, 8,
545      7, 7, 8, 8, 8, 8});
546 
547   // clang-format on
548   test::ExpectTensorEqual<float>(expected, *GetOutput(0));
549 }
550 
551 INSTANTIATE_TEST_SUITE_P(ResizeNearestNeighborOpTestCpu,
552                          ResizeNearestNeighborOpTest,
553                          ::testing::Values(TestDevice::kCPU));
554 INSTANTIATE_TEST_SUITE_P(ResizeNearestNeighborHalfPixelCentersOpTestCpu,
555                          ResizeNearestNeighborHalfPixelCentersOpTest,
556                          ::testing::Values(TestDevice::kCPU));
557 INSTANTIATE_TEST_SUITE_P(ResizeNearestNeighborOpAlignCornersTestCpu,
558                          ResizeNearestNeighborOpAlignCornersTest,
559                          ::testing::Values(TestDevice::kCPU));
560 #if GOOGLE_CUDA
561 // Instantiate tests for kGPU.
562 INSTANTIATE_TEST_SUITE_P(ResizeNearestNeighborOpTestGpu,
563                          ResizeNearestNeighborOpTest,
564                          ::testing::Values(TestDevice::kGPU));
565 INSTANTIATE_TEST_SUITE_P(ResizeNearestNeighborHalfPixelCentersOpTestGpu,
566                          ResizeNearestNeighborHalfPixelCentersOpTest,
567                          ::testing::Values(TestDevice::kGPU));
568 INSTANTIATE_TEST_SUITE_P(ResizeNearestNeighborOpAlignCornersTestGpu,
569                          ResizeNearestNeighborOpAlignCornersTest,
570                          ::testing::Values(TestDevice::kGPU));
571 #endif  // GOOGLE_CUDA
572 }  // namespace tensorflow
573