tf.all_varibles与tf.global_variables的比较

在运行pointer-generator代码时出现了如下报错:

WARNING:tensorflow:From/home/shirveon/env/local/lib/python2.7/site-packages/tensorflow/python/util/tf_should_use.py:170: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.
Instructions for updating:
Use `tf.global_variables_initializer` instead.
WARNING:tensorflow:From run_summarization.py:116: all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02.
Instructions for updating:
Please use tf.global_variables instead.

根据报错信息我将代码中tf.all_variables替换成tf.global_variables,tf.initial_all_variables替换成tf.global_variables,成功解决了这个问题。

tf.global_variables或者tf.all_variables的功能均为获取程序中的变量,不同的版本是不同的,目前的tensorflow多用前一个函数,返回的值是变量的一个列表。

import tensorflow as tf
import numpy as np

v = tf.Variables(tf.constant(0.0, shape =[1],dtype = tf.float32), name = 'v')
v1 = tf.Variable(tf.constant(5, shape = [1], dtype = tf.tloat32,), name='v1')

variables = tf.global_variables()

print(variables[0].name)
print(variables[1].name)

#v:0
#v1:0
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值