代码拉取完成,页面将自动刷新
class tf.nn.softmax_cross_entropy_with_logits(
_sentinel=None,
labels=None,
logits=None,
dim=-1,
name=None,
axis=None
)
For more information, see tf.nn.softmax_cross_entropy_with_logits.
class mindspore.nn.SoftmaxCrossEntropyWithLogits(
sparse=False,
reduction='none'
)(logits, labels)
For more information, see mindspore.nn.SoftmaxCrossEntropyWithLogits.
TensorFlow: The shape of labels and logits must be the same, and the reduction parameter is not provided, which cannot calculate mean or sum for loss.
MindSpore: Sparse matrices for labels are supported and mean or sum for loss can be calculated through the reduction parameter.
# The following implements SoftmaxCrossEntropyWithLogits with MindSpore.
import numpy as np
import tensorflow as tf
import mindspore as ms
import mindspore.nn as nn
loss = nn.SoftmaxCrossEntropyWithLogits(sparse=True, reduction='sum')
logits = ms.Tensor(np.array([[3, 5, 6, 9], [42, 12, 32, 72]]), ms.float32)
labels_np = np.array([1, 0]).astype(np.int32)
labels = ms.Tensor(labels_np)
output = loss(logits, labels)
print(output)
# Out:
# 34.068203
# The following implements softmax_cross_entropy_with_logits with TensorFlow.
logits = tf.constant([[3, 5, 6, 9], [42, 12, 32, 72]], dtype=tf.float32)
labels = tf.constant([[0, 1, 0, 0], [1, 0, 0, 0]], dtype=tf.float32)
output = tf.nn.softmax_cross_entropy_with_logits(labels=labels, logits=logits)
ss = tf.Session()
ss.run(output)
# out
# array([ 4.068202, 30. ], dtype=float32)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。