Created
August 20, 2020 04:05
-
-
Save nahidalam/588ab134c41ef84d9afa310def5a4fa9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
optimizer = tf.keras.optimizers.Adam() | |
loss_object = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True, reduction='none') | |
def loss_function(real, pred): | |
mask = tf.math.logical_not(tf.math.equal(real, 0)) | |
loss_ = loss_object(real, pred) | |
mask = tf.cast(mask, dtype=loss_.dtype) | |
loss_ *= mask | |
return tf.reduce_mean(loss_) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment