|
19 | 19 | import pytest
|
20 | 20 | import numpy as np
|
21 | 21 | import tensorflow as tf
|
22 |
| -from absl.testing import parameterized |
| 22 | + |
23 | 23 | from tensorflow_addons.layers.tlu import TLU
|
24 | 24 | from tensorflow_addons.utils import test_utils
|
25 | 25 |
|
26 | 26 |
|
27 |
| -@parameterized.parameters([np.float16, np.float32, np.float64]) |
28 |
| -@test_utils.run_all_in_graph_and_eager_modes |
29 |
| -class TestTLU(tf.test.TestCase): |
30 |
| - def test_random(self, dtype): |
31 |
| - x = np.array([[-2.5, 0.0, 0.3]]).astype(dtype) |
32 |
| - val = np.array([[0.0, 0.0, 0.3]]).astype(dtype) |
33 |
| - test_utils.layer_test( |
34 |
| - TLU, kwargs={"dtype": dtype}, input_data=x, expected_output=val |
35 |
| - ) |
36 |
| - |
37 |
| - def test_affine(self, dtype): |
38 |
| - x = np.array([[-2.5, 0.0, 0.3]]).astype(dtype) |
39 |
| - val = np.array([[-1.5, 1.0, 1.3]]).astype(dtype) |
40 |
| - test_utils.layer_test( |
41 |
| - TLU, |
42 |
| - kwargs={ |
43 |
| - "affine": True, |
44 |
| - "dtype": dtype, |
45 |
| - "alpha_initializer": "ones", |
46 |
| - "tau_initializer": "ones", |
47 |
| - }, |
48 |
| - input_data=x, |
49 |
| - expected_output=val, |
50 |
| - ) |
51 |
| - |
52 |
| - def test_serialization(self, dtype): |
53 |
| - tlu = TLU( |
54 |
| - affine=True, alpha_initializer="ones", tau_initializer="ones", dtype=dtype |
55 |
| - ) |
56 |
| - serialized_tlu = tf.keras.layers.serialize(tlu) |
57 |
| - new_layer = tf.keras.layers.deserialize(serialized_tlu) |
58 |
| - self.assertEqual(tlu.get_config(), new_layer.get_config()) |
| 27 | +@pytest.mark.usefixtures("maybe_run_functions_eagerly") |
| 28 | +@pytest.mark.parametrize("dtype", [np.float16, np.float32, np.float64]) |
| 29 | +def test_random(dtype): |
| 30 | + x = np.array([[-2.5, 0.0, 0.3]]).astype(dtype) |
| 31 | + val = np.array([[0.0, 0.0, 0.3]]).astype(dtype) |
| 32 | + test_utils.layer_test( |
| 33 | + TLU, kwargs={"dtype": dtype}, input_data=x, expected_output=val |
| 34 | + ) |
| 35 | + |
| 36 | + |
| 37 | +@pytest.mark.usefixtures("maybe_run_functions_eagerly") |
| 38 | +@pytest.mark.parametrize("dtype", [np.float16, np.float32, np.float64]) |
| 39 | +def test_affine(dtype): |
| 40 | + x = np.array([[-2.5, 0.0, 0.3]]).astype(dtype) |
| 41 | + val = np.array([[-1.5, 1.0, 1.3]]).astype(dtype) |
| 42 | + test_utils.layer_test( |
| 43 | + TLU, |
| 44 | + kwargs={ |
| 45 | + "affine": True, |
| 46 | + "dtype": dtype, |
| 47 | + "alpha_initializer": "ones", |
| 48 | + "tau_initializer": "ones", |
| 49 | + }, |
| 50 | + input_data=x, |
| 51 | + expected_output=val, |
| 52 | + ) |
| 53 | + |
| 54 | + |
| 55 | +@pytest.mark.parametrize("dtype", [np.float16, np.float32, np.float64]) |
| 56 | +def test_serialization(dtype): |
| 57 | + tlu = TLU( |
| 58 | + affine=True, alpha_initializer="ones", tau_initializer="ones", dtype=dtype |
| 59 | + ) |
| 60 | + serialized_tlu = tf.keras.layers.serialize(tlu) |
| 61 | + new_layer = tf.keras.layers.deserialize(serialized_tlu) |
| 62 | + assert tlu.get_config() == new_layer.get_config() |
59 | 63 |
|
60 | 64 |
|
61 | 65 | if __name__ == "__main__":
|
|
0 commit comments