稀疏_分类_交叉熵的标签平滑

Ham*_*d K 4 keras tensorflow loss-function

根据 Tensorflow 文档,可以通过添加 label_smoothing 参数来向 categorical_crossentropy 添加标签平滑。我的问题是稀疏分类交叉熵损失怎么样。此损失函数没有 label_smoothing 参数。

Bjö*_*ist 6

编写自己的损失函数很容易:

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)
Run Code Online (Sandbox Code Playgroud)