Preface
在实践《TensorFlow实战Google深度学习框架》一书中的代码时,遇到了一点问题,做下记录
3.1.2计算图的使用 部分
1 | g1 = tf.Graph() |
TypeError: __init__() got an unexpected keyword argument 'shape'
这里出现这个错误是因为tensorflow
版本不一致,书上的是旧版本(0.9.0),而我电脑上安装的是1.8.0
1 | tf.__version__ |
修改为如下代码1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17g1 = tf.Graph()
with g1.as_default():
v = tf.get_variable("v", initializer=tf.zeros_initializer()(shape=[1]))
g2 = tf.Graph()
with g2.as_default():
v = tf.get_variable("v", initializer=tf.zeros_initializer()(shape=[1]))
with tf.Session(graph = g1) as sess:
tf.initialize_all_variables().run()
with tf.variable_scope("", reuse = True):
print(sess.run(tf.get_variable("v")))
with tf.Session(graph = g2) as sess:
tf.initialize_all_variables().run()
with tf.variable_scope("", reuse = True):
print(sess.run(tf.get_variable("v")))
这里抛出了一个警告
1 | WARNING:tensorflow:From /usr/local/lib/python3.5/dist-packages/tensorflow/python/util/tf_should_use.py:118: initialize_all_variables (from tensorflow.python.ops.variables) is deprecated and will be removed after 2017-03-02. |
替换掉initialize_all_variables
即可
1 | g1 = tf.Graph() |
参考
《TensorFlow实战Google深度学习框架》
终端命令查看TensorFlow版本号及路径
TypeError: init() got an unexpected keyword argument ‘shape’