Created by: ceci3
Add bce_loss op, paddle.nn.loss.BCELoss(weight=None, reduction='mean')
.
base format is Out = -1 * (label * log(input) + (1 - label) * log(1 - input))
examples:
import paddle.fluid as fluid
import numpy as np
input = fluid.data(name="input", shape=[3, 1])
label = fluid.data(name="label", shape=[3, 1])
output = fluid.layers.bce_loss(input,label)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
input_data = np.array([0.5, 0.6, 0.7]).astype("float32")
label_data = np.array([1.0, 0.0, 1.0]).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.65537095], dtype=float32)]