[Tensorflow] 参数保存剖析

在tf.global_variables() 里可以看到所有参数
print( tf.global_variables() )
print( sess.run(tf.global_variables() ) 显示其中的数值

这里的名称 'Layer1' 是通过tf.variable_scope() 设置, weights是variable的name,
[<tf.Variable 'Layer1/weights:0' shape=(3072, 120) dtype=float32_ref>,
 <tf.Variable 'Layer1/biases:0' shape=(120,) dtype=float32_ref>, 
<tf.Variable 'Layer2/weights:0' shape=(120, 10) dtype=float32_ref>, 
<tf.Variable 'Layer2/biases:0' shape=(10,) dtype=float32_ref>,
 <tf.Variable 'global_step:0' shape=() dtype=int32_ref>]

关于 :0 官方没有明确解释
As far as I know it means “variable bar after 0th iteration” (stackoverflow)

其中variable有许多参数

demo_weights = tf.get_variable(
      name='weights',
      shape=[128, 64],
      initializer=tf.truncated_normal_initializer(
        stddev=1.0 / np.sqrt(float(128))
    ))

print("demo_weights")
print(demo_weights)
print(demo_weights.name)
print(demo_weights.initial_value)
print(demo_weights.dtype)
print(demo_weights.shape)
print(demo_weights.initializer)

所以如何部分载入参数呢

这里 v2, v3 都是variables , 可以通过在tf.global_variables 或其他方式找需要载入的参数
saver = tf.train.Saver([v2]+[v3])
saver.restore(sess, ckpt)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值