Reputation: 11
I am using Huber loss implementation in tf.keras in tensorflow 1.14.0 as follows:
huber_keras_loss = tf.keras.losses.Huber(
delta=delta,
reduction=tf.keras.losses.Reduction.SUM,
name='huber_loss'
)
I am getting the error AttributeError: module 'tensorflow.python.keras.api._v1.keras.losses' has no attribute 'Reduction'
I have tried using tf.losses.Reduction, tf.compat.v2.losses.Reduction nothing seems to work.
Did tensorflow remove Reduction from tf.keras.losses, it is strange if they did so because their documentation still shows: https://www.tensorflow.org/versions/r1.14/api_docs/python/tf/keras/losses/Huber#args
Upvotes: 1
Views: 6466
Reputation: 21
When I get an error similar to that, applying tf.compat.v1.
usually works.
This is the specific function where I applied it:
tf.compat.v1.losses.sparse_softmax_cross_entropy(labels=labels, logits=output)
I also applied it to similar functions and it worked.
Upvotes: 0
Reputation: 36
Replacing
tf.keras.losses.Reduction
with
tf.compat.v1.losses.Reduction
solved the issue for me in TensorFlow 1.14.0
Upvotes: 1
Reputation: 90
I ran into a similar problem when I installed the tensorflow 1.14.0. What I did to get this to work was to go to upgrade the tensorflow which seemed to revert me to 1.12.0.
pip install --upgrade tensorflow
Upvotes: 0