mse_loss

paddle.fluid.layers.mse_loss(input, label)[source]

This op accepts input predications and target label and returns the mean square error.

The loss can be described as:

\[Out = MEAN((input - label)^2)\]
Parameters
  • input (Variable) – Input tensor, the data type should be float32.

  • label (Variable) – Label tensor, the data type should be float32.

Returns

The tensor variable storing the mean square error difference of input and label.

Return type

Variable

Return type: Variable.

Examples

System Message: ERROR/3 (/usr/local/lib/python2.7/dist-packages/paddle/fluid/layers/loss.py:docstring of paddle.fluid.layers.mse_loss, line 21)

Error in “code-block” directive: maximum 1 argument(s) allowed, 30 supplied.

.. code-block:: python
    # declarative mode
    import paddle.fluid as fluid
    import numpy as np
    input = fluid.data(name="input", shape=[1])
    label = fluid.data(name="label", shape=[1])
    output = fluid.layers.mse_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.04000002], dtype=float32)]

    # imperative mode
    import paddle.fluid.dygraph as dg

    with dg.guard(place) as g:
        input = dg.to_variable(input_data)
        label = dg.to_variable(label_data)
        output = fluid.layers.mse_loss(input, label)
        print(output.numpy())

        # [0.04000002]