mindspore/docs/api/api_python/nn/mindspore.nn.WithLossCell.txt

42 lines
1.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Class mindspore.nn.WithLossCell(backbone, loss_fn)
包含损失函数的Cell。
封装`backbone`和`loss_fn`。此Cell接受数据和标签作为输入并将返回损失函数作为计算结果。
参数:
backbone (Cell):要封装的目标网络。
loss_fn (Cell):用于计算损失函数。
输入:
- **data** Tensor - shape为:math:`(N, \ldots)`的Tensor。
- **label** Tensor - shape为:math:`(N, \ldots)`的Tensor。
输出:
Tensorloss值其shape通常为:math:`()`。
异常:
TypeError`data`或`label`的数据类型既不是float16也不是float32。
支持平台:
``Ascend`` ``GPU`` ``CPU``
示例:
>>> net = Net()
>>> loss_fn = nn.SoftmaxCrossEntropyWithLogits(sparse=False)
>>> net_with_criterion = nn.WithLossCell(net, loss_fn)
>>>
>>> batch_size = 2
>>> data = Tensor(np.ones([batch_size, 1, 32, 32]).astype(np.float32) * 0.01)
>>> label = Tensor(np.ones([batch_size, 10]).astype(np.float32))
>>>
>>> output_data = net_with_criterion(data, label)
backbone_network
获取骨干网络。
返回:
Cell骨干网络。