mindspore.nn.LossBase

class mindspore.nn.LossBase(reduction='mean')[source]

Base class for other losses.

Other losses derived from this should implement their own construct and use method self.get_loss to apply reduction to loss values.

Parameters

reduction (str) – Type of reduction to be applied to loss. The optional values are “mean”, “sum”, and “none”. Default: “mean”.

Raises

ValueError – If reduction is not one of ‘none’, ‘mean’, ‘sum’.

Supported Platforms:

Ascend GPU CPU

get_loss(x, weights=1.0)[source]

Computes the weighted loss.

Parameters
  • weights (Union[float, Tensor]) – Optional Tensor whose rank is either 0, or the same rank as inputs,

  • (i.e. (and must be broadcastable to inputs) –

  • 1 (all dimensions must be either) –

:param : :param or the same as the corresponding inputs dimension).: