Print

paddle.fluid.layers.Print(input, first_n=-1, message=None, summarize=20, print_tensor_name=True, print_tensor_type=True, print_tensor_shape=True, print_tensor_lod=True, print_phase='both')[source]

Print operator

This creates a print op that will print when a tensor is accessed.

Wraps the tensor passed in so that whenever that a tensor is accessed, the message message is printed, along with the current value of the tensor t.

Parameters
  • input (Variable) – A Tensor to print.

  • summarize (int) – Number of elements in the tensor to be print. If it’s vaule is -1, then all elements in the tensor will be print.

  • message (str) – A string message to print as a prefix.

  • first_n (int) – Only log first_n number of times.

  • print_tensor_name (bool, optional) – Print the tensor name. Default: True.

  • print_tensor_type (bool, optional) – Print the tensor type. Defaultt: True.

  • print_tensor_shape (bool, optional) – Print the tensor shape. Default: True.

  • print_tensor_lod (bool, optional) – Print the tensor lod. Default: True.

  • print_phase (str) – Which phase to displace, including ‘forward’, ‘backward’ and ‘both’. Default: ‘both’. If set to ‘backward’, will only print the gradients of input tensor; If set to ‘both’, will both print the input tensor itself and the gradients of input tensor.

Returns

Output tensor.

Return type

Variable

Notes

The input and output are two different variables, and in the following process, you should use the output variable but not the input, otherwise, the print layer doesn’t have backward.

Examples

import paddle.fluid as fluid

input = fluid.layers.fill_constant(shape=[10,2], value=3, dtype='int64')
input = fluid.layers.Print(input, message="The content of input layer:")

main_program = fluid.default_main_program()
exe = fluid.Executor(fluid.CPUPlace())
exe.run(main_program)
Output at runtime:
The content of input layer:     The place is:CPUPlace
Tensor[fill_constant_0.tmp_0]
    shape: [10,2,]
    dtype: x
    data: 3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,