tf.losses类中的交叉熵函数

tf.losses类中的交叉熵函数:

tf.losses.softmax_cross_entropy(
onehot_labels,
logits,
weights=1.0,
label_smoothing=0,
scope=None,
loss_collection=tf.GraphKeys.LOSSES,
reduction=Reduction.SUM_BY_NONZERO_WEIGHTS
)
onehot_labels: 输入的one-hot标签真值
logits: 分类网络的输出
weights: loss函数的系数,可以是标量或张量,当其实张量时,shape必须是[batch_size],每个元素对应一个样本。
loss_collection: 损失函数将被添加到哪里,默认加到计算图的LOSSES部分
reduction: (作用不太明了)

tf.losses.sparse_softmax_cross_entropy(
labels,
logits,
weights=1.0,
scope=None,
loss_collection=tf.GraphKeys.LOSSES,
reduction=Reduction.SUM_BY_NONZERO_WEIGHTS
)
labels:不需要是one-hot编码,但必须是[0, num_classes)区间内的整数。

tf.losses.sigmoid_cross_entropy(
multi_class_labels,
logits,
weights=1.0,
label_smoothing=0,
scope=None,
loss_collection=tf.GraphKeys.LOSSES,
reduction=Reduction.SUM_BY_NONZERO_WEIGHTS
)
multi_class_labels: [batch_size, num_classes]取值为 {0, 1}.
label_smoothing: 如果非零,那么将把标签朝着值为0.5的方向平滑。new_multiclass_labels = multiclass_labels * (1 - label_smoothing)+ 0.5 * label_smoothing

猜你喜欢

转载自blog.csdn.net/fushilei19950818/article/details/82153283