From 4809fc583ee178c277291792f76d6758c5873e34 Mon Sep 17 00:00:00 2001 From: Tzu-Wei Sung Date: Sun, 16 Jun 2019 00:47:08 +0800 Subject: [PATCH] make tests compatible with graph mode --- tensorflow_addons/image/distort_image_ops.py | 3 --- .../image/distort_image_ops_test.py | 24 +++++++++---------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/tensorflow_addons/image/distort_image_ops.py b/tensorflow_addons/image/distort_image_ops.py index a07305ed5f..783fa948c3 100644 --- a/tensorflow_addons/image/distort_image_ops.py +++ b/tensorflow_addons/image/distort_image_ops.py @@ -139,9 +139,6 @@ def adjust_hsv_in_yiq(image, with tf.name_scope(name or "adjust_hsv_in_yiq"): image = tf.convert_to_tensor(image, name="image") - if image.shape.rank < 3: - raise ValueError("input must be at least rank 3.") - # Remember original dtype to so we can convert back if needed orig_dtype = image.dtype flt_image = tf.image.convert_image_dtype(image, tf.dtypes.float32) diff --git a/tensorflow_addons/image/distort_image_ops_test.py b/tensorflow_addons/image/distort_image_ops_test.py index 573511b38e..f2cbe594c7 100644 --- a/tensorflow_addons/image/distort_image_ops_test.py +++ b/tensorflow_addons/image/distort_image_ops_test.py @@ -102,18 +102,18 @@ def test_adjust_random_hue_in_yiq(self): y_tf = self._adjust_hue_in_yiq_tf(x_np, delta_h) self.assertAllClose(y_tf, y_np, rtol=2e-4, atol=1e-4) - # TODO: run in both graph and eager modes + @test_utils.run_in_graph_and_eager_modes def test_invalid_shapes(self): x_np = np.random.rand(2, 3) * 255. delta_h = np.random.rand() * 2.0 - 1.0 with self.assertRaisesRegexp(ValueError, - "input must be at least rank 3."): - self._adjust_hue_in_yiq_tf(x_np, delta_h) + "Shape must be at least rank 3"): + self.evaluate(self._adjust_hue_in_yiq_tf(x_np, delta_h)) x_np = np.random.rand(4, 2, 4) * 255. delta_h = np.random.rand() * 2.0 - 1.0 with self.assertRaisesOpError("input must have 3 channels " "but instead has 4 channels"): - self._adjust_hue_in_yiq_tf(x_np, delta_h) + self.evaluate(self._adjust_hue_in_yiq_tf(x_np, delta_h)) class AdjustValueInYiqTest(tf.test.TestCase): @@ -163,18 +163,18 @@ def test_adjust_random_value_in_yiq(self): y_tf = self._adjust_value_in_yiq_tf(x_np, scale) self.assertAllClose(y_tf, y_np, rtol=2e-4, atol=1e-4) - # TODO: run in both graph and eager modes + @test_utils.run_in_graph_and_eager_modes def test_invalid_shapes(self): x_np = np.random.rand(2, 3) * 255. scale = np.random.rand() * 2.0 - 1.0 with self.assertRaisesRegexp(ValueError, - "input must be at least rank 3."): - self._adjust_value_in_yiq_tf(x_np, scale) + "Shape must be at least rank 3"): + self.evaluate(self._adjust_value_in_yiq_tf(x_np, scale)) x_np = np.random.rand(4, 2, 4) * 255. scale = np.random.rand() * 2.0 - 1.0 with self.assertRaisesOpError("input must have 3 channels " "but instead has 4 channels"): - self._adjust_value_in_yiq_tf(x_np, scale) + self.evaluate(self._adjust_value_in_yiq_tf(x_np, scale)) class AdjustSaturationInYiqTest(tf.test.TestCase): @@ -228,18 +228,18 @@ def test_adjust_random_saturation_in_yiq(self): y_tf = self._adjust_saturation_in_yiq_tf(x_np, scale) self.assertAllClose(y_tf, y_baseline, rtol=2e-4, atol=1e-4) - # TODO: run in both graph and eager modes + @test_utils.run_in_graph_and_eager_modes def test_invalid_shapes(self): x_np = np.random.rand(2, 3) * 255. scale = np.random.rand() * 2.0 - 1.0 with self.assertRaisesRegexp(ValueError, - "input must be at least rank 3."): - self._adjust_saturation_in_yiq_tf(x_np, scale) + "Shape must be at least rank 3"): + self.evaluate(self._adjust_saturation_in_yiq_tf(x_np, scale)) x_np = np.random.rand(4, 2, 4) * 255. scale = np.random.rand() * 2.0 - 1.0 with self.assertRaisesOpError("input must have 3 channels " "but instead has 4 channels"): - self._adjust_saturation_in_yiq_tf(x_np, scale) + self.evaluate(self._adjust_saturation_in_yiq_tf(x_np, scale)) # TODO: get rid of sessions