Created
November 17, 2020 17:11
-
-
Save Shivam-316/48a534b3b75f628cb905ec568205d20d 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=keras.optimizers.Adam() | |
loss=keras.losses.SparseCategoricalCrossentropy(from_logits=True,reduction='none') | |
def loss_fn(true,pred): | |
mask = tf.math.logical_not(tf.math.equal(true, 0)) | |
loss_=loss(true,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