# 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

oneflow.Tensor

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)

__init__(reduction: str = 'mean')None

Initialize self. See help(type(self)) for accurate signature.

Methods

 __call__(*args, **kwargs) Call self as a function. __delattr__(name, /) Implement delattr(self, name). __dir__() Default dir() implementation. __eq__(value, /) Return self==value. __format__(format_spec, /) Default object formatter. __ge__(value, /) Return self>=value. __getattr__(name) __getattribute__(name, /) Return getattr(self, name). __gt__(value, /) Return self>value. __hash__() Return hash(self). __init__([reduction]) Initialize self. __init_subclass__ This method is called when a class is subclassed. __le__(value, /) Return self<=value. __lt__(value, /) Return self