Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 15 additions & 8 deletions tensorflow_addons/image/distort_image_ops_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import numpy as np

import tensorflow as tf
from tensorflow_addons.image import distort_image_ops
from tensorflow.python.eager import context

# from tensorflow_addons.utils import test_utils
from tensorflow_addons.image import distort_image_ops
from tensorflow_addons.utils import test_utils


# TODO: #373 Get this to run in graph mode as well
# @test_utils.run_all_in_graph_and_eager_modes
@test_utils.run_all_in_graph_and_eager_modes
class AdjustHueInYiqTest(tf.test.TestCase):
def _adjust_hue_in_yiq_np(self, x_np, delta_h):
"""Rotate hue in YIQ space.
Expand Down Expand Up @@ -101,11 +101,14 @@ 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: #373 Get this to run in graph mode as well
def test_invalid_shapes(self):
x_np = np.random.rand(2, 3) * 255.
delta_h = np.random.rand() * 2.0 - 1.0
with self.assertRaises((tf.errors.InvalidArgumentError, ValueError)):
self.evaluate(self._adjust_hue_in_yiq_tf(x_np, delta_h))
if not context.executing_eagerly():
self.skipTest("This test does not work in the graph mode yet.")
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 "
Expand All @@ -132,8 +135,7 @@ def test_random_hsv_in_yiq_unknown_shape(self):
self.assertAllEqual(fn(image_tf), fn(image_tf))


# TODO: #373 Get this to run in graph mode as well
# @test_utils.run_all_in_graph_and_eager_modes
@test_utils.run_all_in_graph_and_eager_modes
class AdjustValueInYiqTest(tf.test.TestCase):
def _adjust_value_in_yiq_np(self, x_np, scale):
return x_np * scale
Expand Down Expand Up @@ -180,20 +182,22 @@ 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: #373 Get this to run in graph mode as well
def test_invalid_shapes(self):
x_np = np.random.rand(2, 3) * 255.
scale = np.random.rand() * 2.0 - 1.0
with self.assertRaises((tf.errors.InvalidArgumentError, ValueError)):
self.evaluate(self._adjust_value_in_yiq_tf(x_np, scale))
if not context.executing_eagerly():
self.skipTest("This test does not work in the graph mode yet.")
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.evaluate(self._adjust_value_in_yiq_tf(x_np, scale))


# TODO: #373 Get this to run in graph mode as well
# @test_utils.run_all_in_graph_and_eager_modes
@test_utils.run_all_in_graph_and_eager_modes
class AdjustSaturationInYiqTest(tf.test.TestCase):
def _adjust_saturation_in_yiq_tf(self, x_np, scale):
x = tf.constant(x_np)
Expand Down Expand Up @@ -244,11 +248,14 @@ 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: #373 Get this to run in graph mode as well
def test_invalid_shapes(self):
x_np = np.random.rand(2, 3) * 255.
scale = np.random.rand() * 2.0 - 1.0
with self.assertRaises((tf.errors.InvalidArgumentError, ValueError)):
self.evaluate(self._adjust_saturation_in_yiq_tf(x_np, scale))
if not context.executing_eagerly():
self.skipTest("This test does not work in the graph mode yet.")
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 "
Expand Down