uniform values to test zero variance case
@@ -14,7 +14,7 @@ def test_per_image_standardize():
model = MLP(input_shape=input_shape,
layers=[PerImageStandardize(name='output')])
- x = tf.random_normal(shape=input_shape)
+ x = tf.placeholder(shape=input_shape, dtype=tf.float32)
y = model.get_layer(x, 'output')
y_true = tf.map_fn(
@@ -22,6 +22,12 @@ def test_per_image_standardize():
sess = tf.Session()
- y_value, y_true_value = sess.run([y, y_true])
+ # Random values
+ x_random = np.random.rand(*input_shape)
+ y_value, y_true_value = sess.run([y, y_true], feed_dict={x: x_random})
+ assert np.allclose(y_value, y_true_value)
+ # Uniform values to make zero variance
+ x_uniform = np.ones(input_shape)
+ y_value, y_true_value = sess.run([y, y_true], feed_dict={x: x_uniform})
assert np.allclose(y_value, y_true_value)
