按副本数缩放给定正则化损失的总和。
用法
tf.nn.scale_regularization_loss(
regularization_loss
)
参数
-
regularization_loss
正则化损失。
返回
- 标量损失值。
与分配策略和自定义训练循环一起使用:
with strategy.scope():
def compute_loss(self, label, predictions):
per_example_loss = tf.keras.losses.sparse_categorical_crossentropy(
labels, predictions)
# Compute loss that is scaled by sample_weight and by global batch size.
loss = tf.nn.compute_average_loss(
per_example_loss,
sample_weight=sample_weight,
global_batch_size=GLOBAL_BATCH_SIZE)
# Add scaled regularization losses.
loss += tf.nn.scale_regularization_loss(tf.nn.l2_loss(weights))
return loss
相关用法
- Python tf.nn.softmax用法及代码示例
- Python tf.nn.sigmoid_cross_entropy_with_logits用法及代码示例
- Python tf.nn.space_to_depth用法及代码示例
- Python tf.nn.separable_conv2d用法及代码示例
- Python tf.nn.safe_embedding_lookup_sparse用法及代码示例
- Python tf.nn.sparse_softmax_cross_entropy_with_logits用法及代码示例
- Python tf.nn.sampled_softmax_loss用法及代码示例
- Python tf.nn.softmax_cross_entropy_with_logits用法及代码示例
- Python tf.nn.embedding_lookup_sparse用法及代码示例
- Python tf.nn.RNNCellResidualWrapper.set_weights用法及代码示例
- Python tf.nn.dropout用法及代码示例
- Python tf.nn.gelu用法及代码示例
- Python tf.nn.RNNCellDeviceWrapper.set_weights用法及代码示例
- Python tf.nn.embedding_lookup用法及代码示例
- Python tf.nn.RNNCellDeviceWrapper.get_weights用法及代码示例
- Python tf.nn.local_response_normalization用法及代码示例
- Python tf.nn.RNNCellResidualWrapper.add_loss用法及代码示例
- Python tf.nn.max_pool用法及代码示例
- Python tf.nn.RNNCellDropoutWrapper.set_weights用法及代码示例
- Python tf.nn.l2_loss用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.nn.scale_regularization_loss。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。