Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

PR

Just a small problem.

I can fix it online!

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.mint.nn.functional.l1_loss

View Source On Gitee
mindspore.mint.nn.functional.l1_loss(input, target, reduction='mean')[source]

Calculate the mean absolute error between the input value and the target value.

Assuming that the x and y are the predicted value and target value, both are one-dimensional tensors of length N, length N, reduction is set to 'none' , then calculate the loss of x and y without dimensionality reduction.

The formula is as follows:

(x,y)=L={l1,,lN},with ln=|xnyn|,

where N is the batch size.

If reduction is 'mean' or 'sum' , then:

(x,y)={mean(L),if reduction='mean';sum(L),if reduction='sum'.
Parameters
  • input (Tensor) – Predicted value, Tensor of any dimension.

  • target (Tensor) – Target value, usually has the same shape as the input. If input and target have different shapes, make sure they can broadcast to each other.

  • reduction (str, optional) –

    Apply specific reduction method to the output: 'none' , 'mean' , 'sum' . Default: 'mean' .

    • 'none': no reduction will be applied.

    • 'mean': compute and return the mean of elements in the output. Notice: At least one of the input and target is float type when the reduction is 'mean' .

    • 'sum': the output elements will be summed.

Returns

Tensor or Scalar, if reduction is 'none' , return a Tensor with same shape and dtype as input. Otherwise, a scalar value will be returned.

Raises
  • TypeError – If input is not a Tensor.

  • TypeError – If target is not a Tensor.

  • ValueError – If reduction is not one of 'none' , 'mean' or 'sum' .

Supported Platforms:

Ascend

Examples

>>> from mindspore import Tensor, mint
>>> from mindspore import dtype as mstype
>>> x = Tensor([[1, 2, 3], [4, 5, 6]], mstype.float32)
>>> target = Tensor([[6, 5, 4], [3, 2, 1]], mstype.float32)
>>> output = mint.nn.functional.l1_loss(x, target, reduction="mean")
>>> print(output)
3.0