Hi,
I have a layer which I want to behave differently at test time than at training time. How do I do this with tf.keras?
Upon reading the documentation, I suspected the code below would work, but it doesn't. Please help.
class UniformNoiseLayer(tf.keras.layers.Layer):
def __init__(self, **kwargs):
super(UniformNoiseLayer, self).__init__(**kwargs)
def call(self, input):
if tf.keras.backend.learning_phase():
return input + tf.random.uniform(tf.shape(input), minval= -0.5, maxval = 0.5, dtype=tf.float32, name='uniform_distribution')
else:
return tf.round(input)