Ham*_*d K 4 keras tensorflow loss-function
根据 Tensorflow 文档,可以通过添加 label_smoothing 参数来向 categorical_crossentropy 添加标签平滑。我的问题是稀疏分类交叉熵损失怎么样。此损失函数没有 label_smoothing 参数。
编写自己的损失函数很容易:
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)
| 归档时间: |
|
| 查看次数: |
3168 次 |
| 最近记录: |