From 058aa3a305d1e20535402a3bfad8288cb1bbbe48 Mon Sep 17 00:00:00 2001 From: Scott Zhu Date: Tue, 13 Oct 2020 10:25:19 -0700 Subject: [PATCH] Update the image_test to proper AST scope. PiperOrigin-RevId: 336904200 Change-Id: I87269130e4a90bfbb0fdf9854fb55f0f32a6de01 --- .../python/keras/preprocessing/image_test.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/tensorflow/python/keras/preprocessing/image_test.py b/tensorflow/python/keras/preprocessing/image_test.py index 78cec643570..2f22b92f05a 100644 --- a/tensorflow/python/keras/preprocessing/image_test.py +++ b/tensorflow/python/keras/preprocessing/image_test.py @@ -22,6 +22,7 @@ import os import shutil import tempfile +from absl.testing import parameterized import numpy as np from tensorflow.python.data import Dataset @@ -71,18 +72,21 @@ class TestImage(keras_parameterized.TestCase): output = preprocessing_image.smart_resize(test_input, size=(5, 15)) self.assertListEqual(list(output.shape), [5, 15, 3]) + @parameterized.named_parameters( + ('size1', (50, 50)), + ('size2', (10, 10)), + ('size3', (100, 50)), + ('size4', (5, 15))) @testing_utils.run_v2_only - def test_smart_resize_tf_dataset(self): + def test_smart_resize_tf_dataset(self, size): test_input_np = np.random.random((2, 20, 40, 3)) test_ds = Dataset.from_tensor_slices(test_input_np) resize = lambda img: preprocessing_image.smart_resize(img, size=size) - - for size in [(50, 50), (10, 10), (100, 50), (5, 15)]: - test_ds = test_ds.map(resize) - for sample in test_ds.as_numpy_iterator(): - self.assertIsInstance(sample, np.ndarray) - self.assertListEqual(list(sample.shape), [size[0], size[1], 3]) + test_ds = test_ds.map(resize) + for sample in test_ds.as_numpy_iterator(): + self.assertIsInstance(sample, np.ndarray) + self.assertListEqual(list(sample.shape), [size[0], size[1], 3]) def test_smart_resize_errors(self): with self.assertRaisesRegex(ValueError, 'a tuple of 2 integers'):