Skip to content

Commit ee74c18

Browse files
facaiyseanpmorgan
authored andcommitted
CLN: remove tf_test_util and keras.test_util (#81)
* CLN: remove tf_test_util and keras.test_util
1 parent b8c0597 commit ee74c18

File tree

18 files changed

+69
-53
lines changed

18 files changed

+69
-53
lines changed

tensorflow_addons/activations/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ py_library(
1717

1818
py_test(
1919
name = "sparsemax_py_test",
20-
size = "small",
20+
size = "medium",
2121
srcs = [
2222
"python/sparsemax_test.py",
2323
],

tensorflow_addons/activations/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ must:
1919
#### Testing Requirements
2020
* Simple unittests that demonstrate the layer is behaving as expected.
2121
* When applicable, run all unittests with TensorFlow's
22-
`@run_all_in_graph_and_eager_modes` decorator.
22+
`@run_in_graph_and_eager_modes` (for test method)
23+
or `run_all_in_graph_and_eager_modes` (for TestCase subclass)
24+
decorator.
2325
* Add a `py_test` to this sub-package's BUILD file.
2426

2527
#### Documentation Requirements

tensorflow_addons/custom_ops/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ must:
2020
* Simple unittests that demonstrate the custom op is behaving as
2121
expected.
2222
* When applicable, run all unittests with TensorFlow's
23-
`@run_all_in_graph_and_eager_modes` decorator.
23+
`@run_in_graph_and_eager_modes` (for test method)
24+
or `run_all_in_graph_and_eager_modes` (for TestCase subclass)
25+
decorator.
2426
* Add a `py_test` to the custom-op's BUILD file.
2527

2628
#### Documentation Requirements

tensorflow_addons/custom_ops/image/BUILD

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,15 @@ py_library(
3030
]),
3131
data = [
3232
":python/_image_ops.so",
33+
"//tensorflow_addons/utils:utils_py",
3334
],
3435
srcs_version = "PY2AND3",
3536
)
3637

3738
# TODO: use cuda_py_test later.
3839
py_test(
3940
name = "transform_ops_test",
40-
size = "small",
41+
size = "medium",
4142
srcs = [
4243
"python/transform_test.py",
4344
],

tensorflow_addons/custom_ops/image/python/transform.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ def transform(images,
121121
return output
122122

123123

124+
@tf.function
124125
def compose_transforms(*transforms):
125126
"""Composes the transforms tensors.
126127
@@ -144,6 +145,7 @@ def compose_transforms(*transforms):
144145
return matrices_to_flat_transforms(composed)
145146

146147

148+
@tf.function
147149
def flat_transforms_to_matrices(transforms):
148150
"""Converts projective transforms to affine matrices.
149151
@@ -176,6 +178,7 @@ def flat_transforms_to_matrices(transforms):
176178
tf.constant([-1, 3, 3]))
177179

178180

181+
@tf.function
179182
def matrices_to_flat_transforms(transform_matrices):
180183
"""Converts affine matrices to projective transforms.
181184
@@ -208,6 +211,7 @@ def matrices_to_flat_transforms(transform_matrices):
208211
return transforms[:, :8]
209212

210213

214+
@tf.function
211215
def angles_to_projective_transforms(angles,
212216
image_height,
213217
image_width,

tensorflow_addons/custom_ops/image/python/transform_test.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import numpy as np
2222
import tensorflow as tf
2323

24-
from tensorflow.python.framework import test_util as tf_test_util
2524
from tensorflow.python.ops import gradient_checker
2625
from tensorflow_addons.custom_ops.image.python import transform as transform_ops
26+
from tensorflow_addons.utils.python import test_utils
2727

2828
_DTYPES = set([
2929
tf.dtypes.uint8, tf.dtypes.int32, tf.dtypes.int64, tf.dtypes.float16,
@@ -32,7 +32,7 @@
3232

3333

3434
class ImageOpsTest(tf.test.TestCase):
35-
@tf_test_util.run_all_in_graph_and_eager_modes
35+
@test_utils.run_in_graph_and_eager_modes
3636
def test_compose(self):
3737
for dtype in _DTYPES:
3838
image = tf.constant(
@@ -51,7 +51,7 @@ def test_compose(self):
5151
[[0, 0, 0, 0], [0, 1, 0, 1], [0, 1, 0, 1], [0, 1, 1, 1]],
5252
image_transformed)
5353

54-
@tf_test_util.run_all_in_graph_and_eager_modes
54+
@test_utils.run_in_graph_and_eager_modes
5555
def test_extreme_projective_transform(self):
5656
for dtype in _DTYPES:
5757
image = tf.constant(
@@ -64,7 +64,6 @@ def test_extreme_projective_transform(self):
6464
[[1, 0, 0, 0], [0, 0, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0]],
6565
image_transformed)
6666

67-
@tf_test_util.run_all_in_graph_and_eager_modes
6867
def test_transform_static_output_shape(self):
6968
image = tf.constant([[1., 2.], [3., 4.]])
7069
result = transform_ops.transform(
@@ -118,7 +117,7 @@ def _test_grad_different_shape(self, input_shape, output_shape):
118117
self.assertLess(left_err, 1e-10)
119118

120119
# TODO: switch to TF2 later.
121-
@tf_test_util.run_deprecated_v1
120+
@test_utils.run_deprecated_v1
122121
def test_grad(self):
123122
self._test_grad([16, 16])
124123
self._test_grad([4, 12, 12])
@@ -127,16 +126,15 @@ def test_grad(self):
127126
self._test_grad_different_shape([4, 12, 3], [8, 24, 3])
128127
self._test_grad_different_shape([3, 4, 12, 3], [3, 8, 24, 3])
129128

130-
@tf_test_util.run_all_in_graph_and_eager_modes
129+
@test_utils.run_in_graph_and_eager_modes
131130
def test_transform_data_types(self):
132131
for dtype in _DTYPES:
133132
image = tf.constant([[1, 2], [3, 4]], dtype=dtype)
134-
with self.test_session(use_gpu=True):
135-
self.assertAllEqual(
136-
np.array([[4, 4], [4, 4]]).astype(dtype.as_numpy_dtype()),
137-
transform_ops.transform(image, [1] * 8))
133+
self.assertAllEqual(
134+
np.array([[4, 4], [4, 4]]).astype(dtype.as_numpy_dtype()),
135+
transform_ops.transform(image, [1] * 8))
138136

139-
@tf_test_util.run_all_in_graph_and_eager_modes
137+
@test_utils.run_in_graph_and_eager_modes
140138
def test_transform_eager(self):
141139
image = tf.constant([[1., 2.], [3., 4.]])
142140
self.assertAllEqual(

tensorflow_addons/custom_ops/text/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ py_library(
2727
]),
2828
data = [
2929
":python/_skip_gram_ops.so",
30+
"//tensorflow_addons/utils:utils_py",
3031
],
3132
srcs_version = "PY2AND3",
3233
)

tensorflow_addons/custom_ops/text/python/skip_gram_ops_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@
2222
import os
2323
import tensorflow as tf
2424

25-
from tensorflow.python.framework import test_util as tf_test_util
2625
from tensorflow.python.framework import random_seed
2726
from tensorflow.python.ops import lookup_ops
2827
from tensorflow.python.platform import test
2928
from tensorflow_addons.custom_ops import text
3029
from tensorflow_addons.custom_ops.text.python import skip_gram_ops
30+
from tensorflow_addons.utils.python import test_utils
3131

3232

3333
class SkipGramOpsTest(tf.test.TestCase):
@@ -232,7 +232,7 @@ def test_skip_gram_sample_non_string_input(self):
232232
self.assertAllEqual(expected_tokens, tokens)
233233
self.assertAllEqual(expected_labels, labels)
234234

235-
@tf_test_util.run_deprecated_v1
235+
@test_utils.run_deprecated_v1
236236
def test_skip_gram_sample_errors_v1(self):
237237
"""Tests various errors raised by skip_gram_sample()."""
238238
# input_tensor must be of rank 1.

tensorflow_addons/layers/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ must:
2020
#### Testing Requirements
2121
* Simple unittests that demonstrate the layer is behaving as expected.
2222
* When applicable, run all unittests with TensorFlow's
23-
`@run_all_in_graph_and_eager_modes` decorator.
24-
* Run `keras.testing_utils.layer_test` on the layer.
23+
`@run_in_graph_and_eager_modes` (for test method)
24+
or `run_all_in_graph_and_eager_modes` (for TestCase subclass)
25+
decorator.
26+
* Run `layer_test` on the layer.
2527
* Add a `py_test` to this sub-package's BUILD file.
2628

2729
#### Documentation Requirements

tensorflow_addons/layers/python/maxout_test.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,26 @@
2121
import numpy as np
2222
import tensorflow as tf
2323

24-
from tensorflow.python.keras import testing_utils as keras_test_util
2524
from tensorflow_addons.layers.python.maxout import Maxout
25+
from tensorflow_addons.utils.python import test_utils
2626

2727

28+
@test_utils.run_all_in_graph_and_eager_modes
2829
class MaxOutTest(tf.test.TestCase):
2930
def test_simple(self):
30-
keras_test_util.layer_test(
31+
test_utils.layer_test(
3132
Maxout, kwargs={'num_units': 3}, input_shape=(5, 4, 2, 18))
3233

3334
def test_nchw(self):
34-
keras_test_util.layer_test(
35+
test_utils.layer_test(
3536
Maxout,
3637
kwargs={
3738
'num_units': 4,
3839
'axis': 1
3940
},
4041
input_shape=(2, 20, 3, 6))
4142

42-
keras_test_util.layer_test(
43+
test_utils.layer_test(
4344
Maxout,
4445
kwargs={
4546
'num_units': 4,
@@ -49,21 +50,21 @@ def test_nchw(self):
4950

5051
def test_unknown(self):
5152
inputs = np.random.random((5, 4, 2, 18)).astype('float32')
52-
keras_test_util.layer_test(
53+
test_utils.layer_test(
5354
Maxout,
5455
kwargs={'num_units': 3},
5556
input_shape=(5, 4, 2, None),
5657
input_data=inputs)
5758

58-
keras_test_util.layer_test(
59+
test_utils.layer_test(
5960
Maxout,
6061
kwargs={'num_units': 3},
6162
input_shape=(None, None, None, None),
6263
input_data=inputs)
6364

6465
def test_invalid_shape(self):
6566
with self.assertRaisesRegexp(ValueError, r'number of features'):
66-
keras_test_util.layer_test(
67+
test_utils.layer_test(
6768
Maxout, kwargs={'num_units': 3}, input_shape=(5, 4, 2, 7))
6869

6970

0 commit comments

Comments
 (0)