def scatter(input, index, updates, name=None): """ **Scatter Layer** by Lihang Liu. There's a bug in Python API scatter for parameter checking, please refer to (https://github.com/PaddlePaddle/Paddle/issues/12725). Output is obtained by updating the input on selected indices on the first axis. .. math:: Out = X Out[Ids] = Updates Args: input (Variable): The source input with rank>=1. index (Variable): The index input with rank=1. Its dtype should be int32 or int64 as it is used as indexes. updates (Variable): The updated value of scatter op. name (str|None): The output variable name. Default None. Returns: output (Variable): The output is a tensor with the same shape as input. Examples: .. code-block:: python output = fluid.layers.scatter(input, index, updates) """ helper = LayerHelper('scatter', **locals()) dtype = helper.input_dtype() out = helper.create_tmp_variable(dtype) helper.append_op( type="scatter", inputs={"X": input, "Ids": index, "Updates": updates}, outputs={"Out": out}) return out
def log_loss(input, label, epsilon=1e-4): """ **Negative Log Loss Layer** This layer accepts input predictions and target label and returns the negative log loss. .. math:: Out = -label * log(X + epsilon) - (1 - label) * log(1 - X + epsilon) Args: input: a 2-D tensor with shape [N x 1], where N is the batch size. This input is a probability computed by the previous operator. label: the ground truth which is a 2-D tensor with shape [N x 1], where N is the batch size. epsilon: epsilon Returns: A 2-D tensor with shape [N x 1], the negative log loss. Examples: .. code-block:: python prob = fluid.layers.sigmoid(net) cost = fluid.layers.log_loss(input=prob, label=label) """ helper = LayerHelper('log_loss', **locals()) loss = helper.create_tmp_variable(dtype=input.dtype) helper.append_op( type='log_loss', inputs={'Predicted': [input], 'Labels': [label]}, outputs={'Loss': [loss]}, attrs={'epsilon': epsilon}) return loss