smooth_l1¶
- paddle.fluid.layers.nn. smooth_l1 ( x, y, inside_weight=None, outside_weight=None, sigma=None ) [source]
-
This layer computes the smooth L1 loss for Variable
x
andy
. It takes the first dimension ofx
andy
as batch size. For each instance, it computes the smooth L1 loss element by element first and then sums all the losses. So the shape of output Variable is [batch_size, 1].- Parameters
-
x (Variable) – A tensor with rank at least 2. The input value of smooth L1 loss op with shape [batch_size, dim1, …, dimN]. A LoDTensor or Tensor with type float32.
y (Variable) – A tensor with rank at least 2. The target value of smooth L1 loss op with same shape as
x
. A LoDTensor or Tensor with type float32.inside_weight (Variable|None) – A tensor with rank at least 2. This input is optional and should have same shape with
x
. If provided, the result of (x
-y
) will be multiplied by this tensor element by element. A Tensor with type float32.outside_weight (Variable|None) – A tensor with rank at least 2. This input is optional and should have same shape with
x
. If provided, the out smooth L1 loss will be multiplied by this tensor element by element. A Tensor with type float32.sigma (float|None) – Hyper parameter of smooth L1 loss layer. A float scalar with default value 1.0.
- Returns
-
The output smooth L1 loss with shape [batch_size, 1]. A Tensor with type float32.
- Return type
-
Variable
Examples
import paddle.fluid as fluid import numpy as np import paddle paddle.enable_static() data = fluid.data(name="x", shape=[-1, 3], dtype="float32") label = fluid.data(name="y", shape=[-1, 3], dtype="float32") result = fluid.layers.smooth_l1(data,label) place = fluid.CPUPlace() exe = fluid.Executor(place) exe.run(fluid.default_startup_program()) x = np.random.rand(3,3).astype("float32") y = np.random.rand(3,3).astype("float32") output= exe.run(feed={"x":x, "y":y}, fetch_list=[result]) print(output) #[array([[0.08220536], # [0.36652038], # [0.20541131]], dtype=float32)]