better tests for invert with variance != 1.0
@@ -228,25 +228,26 @@ class NormalizationTest(
self.assertAllEqual(output.dtype, tf.float64)
def test_invert(self):
- data = np.array([0.0, 2.0, 0.0, 2.0])
- norm = normalization.Normalization(mean=1.0, variance=1.0)
+ input_data = np.array([0.0, 4.0, 0.0, 4.0])
+ norm = normalization.Normalization(mean=2.0, variance=4.0)
inv_norm = normalization.Normalization(
- mean=1.0, variance=1.0, invert=True
+ mean=2.0, variance=4.0, invert=True
)
- output = norm(data)
+ output = norm(input_data)
output2 = inv_norm(output)
self.assertListEqual(output2.shape.as_list(), [4])
- self.assertAllClose(output2, [0.0, 2.0, 0.0, 2.0])
+ self.assertAllClose(input_data, output2)
@test_utils.run_v2_only
def test_invert_adapt(self):
- input_data = [[0.0], [2.0], [0.0], [2.0]]
+ input_data = [[0.0], [4.0], [0.0], [4.0]]
norm = keras.layers.Normalization(axis=-1)
norm.adapt(input_data)
inv_norm = keras.layers.Normalization(axis=-1, invert=True)
inv_norm.adapt(input_data)
output = norm(input_data)
output2 = inv_norm(output)
+ self.assertListEqual(output2.shape.as_list(), [4])
self.assertAllClose(input_data, output2)
