使用 tf.nn.sigmoid_cross_entropy_with_logits 创建 cross-entropy 损失。
用法
tf.compat.v1.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}。 -
logitsFloat[batch_size, num_classes]记录网络的输出。 -
weights可选Tensor,其秩为0,或与multi_class_labels相同的秩,并且必须可广播到multi_class_labels(即,所有维度必须是1,或与相应的losses维度相同) . -
label_smoothing如果大于0则平滑标签。 -
scope在计算损失时执行的操作的范围。 -
loss_collection将添加损失的集合。 -
reduction适用于损失的减免类型。
返回
-
加权损失
Tensor与logits类型相同。如果reduction是NONE,则它的形状与logits相同;否则,它是标量。
抛出
-
ValueError如果logits的形状与multi_class_labels的形状不匹配,或者如果weights的形状无效,或者如果weights为 None。此外,如果multi_class_labels或logits为无。
weights 作为损失的系数。如果提供了标量,则损失只是按给定值缩放。如果 weights 是形状为 [batch_size] 的张量,则损失权重适用于每个相应的样本。
如果 label_smoothing 不为零,则将标签平滑到 1/2:
new_multiclass_labels = multiclass_labels * (1 - label_smoothing)
+ 0.5 * label_smoothing
eager模式兼容性
loss_collection 参数在即刻执行时被忽略。考虑保持返回值或通过 tf.keras.Model 收集损失。
相关用法
- Python tf.compat.v1.losses.softmax_cross_entropy用法及代码示例
- Python tf.compat.v1.losses.mean_squared_error用法及代码示例
- Python tf.compat.v1.losses.huber_loss用法及代码示例
- Python tf.compat.v1.lookup.StaticHashTable用法及代码示例
- Python tf.compat.v1.lookup.StaticVocabularyTable用法及代码示例
- Python tf.compat.v1.layers.conv3d用法及代码示例
- Python tf.compat.v1.layers.Conv3D用法及代码示例
- Python tf.compat.v1.layers.dense用法及代码示例
- Python tf.compat.v1.layers.AveragePooling3D用法及代码示例
- Python tf.compat.v1.lite.TFLiteConverter用法及代码示例
- Python tf.compat.v1.layers.Conv2DTranspose用法及代码示例
- Python tf.compat.v1.layers.max_pooling3d用法及代码示例
- Python tf.compat.v1.layers.average_pooling1d用法及代码示例
- Python tf.compat.v1.layers.experimental.keras_style_scope用法及代码示例
- Python tf.compat.v1.layers.flatten用法及代码示例
- Python tf.compat.v1.layers.conv1d用法及代码示例
- Python tf.compat.v1.layers.experimental.set_keras_style用法及代码示例
- Python tf.compat.v1.layers.conv2d_transpose用法及代码示例
- Python tf.compat.v1.layers.dropout用法及代码示例
- Python tf.compat.v1.layers.batch_normalization用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.compat.v1.losses.sigmoid_cross_entropy。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
