Issue
Based on the Tensorflow Documentation, one can add label smoothing to categorical_crossentropy by adding label_smoothing argument. My question is what about sparse categorical crossentropy loss. There is no label_smoothing argument for this loss function.
Solution
It's easy to write your own loss function:
from tensorflow.keras.losses import categorical_crossentropy
def scce_with_ls(y, y_hat):
y = tf.one_hot(tf.cast(y, tf.int32), n_classes)
return categorical_crossentropy(y, y_hat, label_smoothing = 0.1)
Answered By - Björn Lindqvist
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.