mindelec.loss.get_loss_metric

mindelec.loss.get_loss_metric(name)[source]

Gets the loss function.

Parameters

name (str) – The name of the loss function.

Returns

Function, the loss function.

Supported Platforms:

Ascend

Examples

>>> import numpy as np
>>> from mindelec.loss import get_loss_metric
>>> import mindspore
>>> from mindspore import Tensor
>>> l1_loss = get_loss_metric('l1_loss')
>>> logits = Tensor(np.array([1, 2, 3]), mindspore.float32)
>>> labels = Tensor(np.array([[1, 1, 1], [1, 2, 2]]), mindspore.float32)
>>> output = l1_loss(logits, labels)
>>> print(output)
0.6666667