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.

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.ops.smooth_l1_loss

mindspore.ops.smooth_l1_loss(input, target, beta=1.0, reduction='none')[source]

Computes smooth L1 loss, a robust L1 loss.

SmoothL1Loss is a Loss similar to MSELoss but less sensitive to outliers as described in the Fast R-CNN by Ross Girshick.

Given two input x, y of length N, the unreduced SmoothL1Loss can be described as follows:

Li={0.5(xiyi)2beta,if |xiyi|<beta|xiyi|0.5beta,otherwise. 

If reduction is not none, then:

L={mean(Li),if reduction='mean';sum(Li),if reduction='sum'.

Here beta controls the point where the loss function changes from quadratic to linear. beta>0 , its default value is 1.0 . N is the batch size.

Warning

This API has poor performance on CPU and it is recommended to run it on the Ascend/GPU.

Parameters
  • input (Tensor) –

    Tensor of shape (N,) where means, any number of additional dimensions.Supported dtypes:

    • Ascend: float16, float32, bfloat16.

    • CPU/GPU: float16, float32, float64.

  • target (Tensor) –

    Ground truth data, tensor of shape (N,).

    • CPU/Ascend: has the same shape as the input, target and input comply with the implicit type conversion rules to make the data types consistent.

    • GPU: has the same shape and dtype as the input.

  • beta (number, optional) –

    A parameter used to control the point where the function will change between L1 to L2 loss. Default: 1.0 .

    • Ascend: The value should be equal to or greater than zero.

    • CPU/GPU: The value should be greater than zero.

  • reduction (str, optional) –

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

    • 'none': no reduction will be applied.

    • 'mean': compute and return the mean of elements in the output.

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

Returns

Tensor, if reduction is 'none', then output is a tensor with the same shape as input. Otherwise, the shape of output tensor is ().

Raises
  • TypeError – If input input, target is not Tensor.

  • RuntimeError – If dtype of input or target is not one of float16, float32, float64, bfloat16.

  • ValueError – If shape of input is not the same as target.

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

  • TypeError – If beta is not a float, int or bool.

  • RuntimeError – If beta is less than or equal to 0.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> logits = Tensor(np.array([1, 2, 3]), mindspore.float32)
>>> labels = Tensor(np.array([1, 2, 2]), mindspore.float32)
>>> output = ops.smooth_l1_loss(logits, labels)
>>> print(output)
[0.  0.  0.5]