Created by: zhiqiu
Add a new public nn API, paddle.nn.loss.L1Loss(reduction='mean')
.
- As the form of class.
- Under module
paddle
directly, instead offluid
. - The functionality of
L1Loss
is to calculate the L1 loss.
usage:
import paddle.fluid as fluid
import paddle
import numpy as np
l1_loss = paddle.nn.loss.L1Loss()
input = fluid.data(name="input", shape=[1])
label = fluid.data(name="label", shape=[1])
output = l1_loss(input, label)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
input_data = np.array([1.5]).astype("float32")
label_data = np.array([1.7]).astype("float32")
output_data = exe.run(fluid.default_main_program(),
feed={"input":input_data, "label":label_data},
fetch_list=[output],
return_numpy=True)
print(output_data) # [array([0.2], dtype=float32)]