layers.Print()并未显示信息
Created by: shaoshenchen
链接地址:https://www.paddlepaddle.org.cn/documentation/docs/zh/api_cn/layers_cn/Print_cn.html#print
源码:
import paddle.fluid as fluid
import paddle
import numpy as np
x = fluid.layers.data(name='x', shape=[1], dtype='float32', lod_level=1)
x = fluid.layers.Print(x, message="The content of input layer:")
y = fluid.layers.data(name='y', shape=[1], dtype='float32', lod_level=2)
out = fluid.layers.sequence_expand(x=x, y=y, ref_level=0)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())
x_d = fluid.create_lod_tensor(np.array([[1.1], [2.2],[3.3],[4.4]]).astype('float32'), [[1,3]], place)
y_d = fluid.create_lod_tensor(np.array([[1.1],[1.1],[1.1],[1.1],[1.1],[1.1]]).astype('float32'), [[1,3], [1,2,1,2]], place)
results = exe.run(fluid.default_main_program(),
feed={'x':x_d, 'y': y_d },
fetch_list=[out],return_numpy=False)
输出: 第一次执行给了个警告:/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/executor.py:804: UserWarning: There are no operators in the program to be executed. If you pass Program manually, please use fluid.program_guard to ensure the current Program is being used. warnings.warn(error_info) 第二次执行没什么都没显示