PaddlePaddle / Paddle

PArallel Distributed Deep LEarning: Machine Learning Framework from Industrial Practice (『飞桨』核心框架,深度学习&机器学习高性能单机、分布式训练和跨平台部署)
http://www.paddlepaddle.org/
Apache License 2.0
22.22k stars 5.58k forks source link

fluid如何获得所有层的名字 #18202

Closed seanxh closed 5 years ago

seanxh commented 5 years ago
import paddle
import paddle.fluid as fluid
import paddle.fluid.core as core
import paddle.fluid.framework as framework
from paddle.fluid.executor import Executor

shape = [1]

gate_size = 10

data = fluid.layers.data(name='data', shape=shape, dtype='float32')
input_forward_proj = fluid.layers.fc(name='fc_0',input=data,
                                             size=gate_size * 4,
                                             act=None,
                                             bias_attr=False)
forward, state = fluid.layers.dynamic_lstm(
    name='blstm_0',
    input=input_forward_proj, size=gate_size * 4,use_peepholes=False)

place = fluid.CPUPlace()
exe = fluid.Executor(place)
exe.run(fluid.default_startup_program())

scope = fluid.global_scope()
print scope.find_var('fc_0.w_0').get_tensor()

请问,我如何知道结构里其它块的名字??类似 fc_0.w_0这种? 同时,我要怎么取得这些参数的值呢??

seiriosPlus commented 5 years ago

可以打印default_main_program.里面有全部layer的参数。

seanxh commented 5 years ago

可以打印default_main_program.里面有全部layer的参数。

got。

print fluid.default_startup_program()

print np.array(fluid.global_scope().find_var('fc_0.w_0').get_tensor())

即可