oneflow.nn.L1Loss¶
-
class
oneflow.nn.
L1Loss
(reduction: str = 'mean')¶ This operator computes the L1 Loss between each element in input and target.
The equation is:
if reduction = “none”:
\[output = |Target - Input|\]if reduction = “mean”:
\[output = \frac{1}{n}\sum_{i=1}^n|Target_i - Input_i|\]if reduction = “sum”:
\[output = \sum_{i=1}^n|Target_i - Input_i|\]- Parameters
input (oneflow.Tensor) – the input Tensor.
target (oneflow.Tensor) – The target Tensor.
reduction (str) – The reduce type, it can be one of “none”, “mean”, “sum”. Defaults to “mean”.
- Returns
The result Tensor.
- Return type
For example:
>>> import oneflow as flow >>> import numpy as np >>> input = flow.tensor([[1, 1, 1], [2, 2, 2], [7, 7, 7]], dtype = flow.float32) >>> target = flow.tensor([[4, 4, 4], [4, 4, 4], [4, 4, 4]], dtype = flow.float32) >>> m = flow.nn.L1Loss(reduction="none") >>> out = m(input, target) >>> out tensor([[3., 3., 3.], [2., 2., 2.], [3., 3., 3.]], dtype=oneflow.float32) >>> m_mean = flow.nn.L1Loss(reduction="mean") >>> out = m_mean(input, target) >>> out tensor(2.6667, dtype=oneflow.float32) >>> m_mean = flow.nn.L1Loss(reduction="sum") >>> out = m_mean(input, target) >>> out tensor(24., dtype=oneflow.float32)