Print¶
- paddle.static. Print ( input, first_n=- 1, message=None, summarize=20, print_tensor_name=True, print_tensor_type=True, print_tensor_shape=True, print_tensor_layout=True, print_tensor_lod=True, print_phase='both' ) [source]
-
- Api_attr
-
Static Graph
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 (Tensor) – A Tensor to print.
first_n (int, optional) – Only log first_n number of times. Default: -1.
message (str, optional) – A string message to print as a prefix. Default: None.
summarize (int, optional) – Number of elements in the tensor to be print. If it’s value is -1, then all elements in the tensor will be print.
print_tensor_name (bool, optional) – Print the tensor name. Default: True.
print_tensor_type (bool, optional) – Print the tensor type. Default: True.
print_tensor_shape (bool, optional) – Print the tensor shape. Default: True.
print_tensor_layout (bool, optional) – Print the tensor layout. Default: True.
print_tensor_lod (bool, optional) – Print the tensor lod. Default: True.
print_phase (str, optional) – 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
-
Tensor
Notes
The input and output are two different Tensor, and in the following process, you should use the output Tensor but not the input, otherwise, the print layer doesn’t have backward.
Examples
>>> import paddle >>> paddle.enable_static() >>> x = paddle.full(shape=[2, 3], fill_value=3, dtype='int64') >>> out = paddle.static.Print(x, message="The content of input layer:") >>> main_program = paddle.static.default_main_program() >>> exe = paddle.static.Executor(place=paddle.CPUPlace()) >>> res = exe.run(main_program, fetch_list=[out]) >>> Variable: fill_constant_1.tmp_0 - message: The content of input layer: - lod: {} - place: Place(cpu) - shape: [2, 3] - layout: NCHW - dtype: int64 - data: [3 3 3 3 3 3] >>> >>> res [array([[3, 3, 3], [3, 3, 3]], dtype=int64)]