Issue
I'm trying to implement a Noise To Signal Ratio loss function in Keras. I translated the code from this repo that works with torch.
Not sure if the tf.math operations that I used do the same stuff as torch's functions. When training, I keep getting loss: nan - val_loss: nan
.
What am I doing wrong?
Any help is appreciated.
Thank you
def noiseToSignalLoss(y_true, y_pred):
losses = tf.math.divide(
tf.math.reduce_sum(
tf.math.pow(
tf.math.abs(
tf.math.subtract(
y_true,
y_pred
)
),
2
),
axis=-1
),
tf.math.reduce_sum(
tf.math.pow(tf.math.abs(y_true),2),
axis=-1
)
)
return tf.reduce_mean(losses, axis=-1)
Solution
Seems like the axis
parameters were wrong. Here's the working Noise To Signal Ratio loss function for Keras, if anyone is interested:
def noiseToSignalLoss(y_true, y_pred):
losses = tf.math.divide(
tf.math.reduce_sum(
tf.math.pow(
tf.math.abs(
tf.math.subtract(
y_true,
y_pred
)
),
2
)
),
tf.math.reduce_sum(
tf.math.pow(tf.math.abs(y_true),2)
)
)
return tf.reduce_mean(losses)
Answered By - Vítor Manfredini
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.