tensorflow官方文档中的sub 和mul中的函数已经在API中改名了
时间:2017-07-29 18:56:34
收藏:0
阅读:16806
在照着tensorflow 官方文档和极客学院中tensorflow中文文档学习tensorflow时,遇到下面的两个问题:
1)AttributeError: module ‘tensorflow‘ has no attribute ‘sub‘
#进入一个交互式Tensorflow会话 import tensorflow as tf sess = tf.InteractiveSession() x = tf.Variable([1.0,2.0]) a = tf.constant([3.0,3.0]) #使用初始化器initalizer op的run()方法初始化‘x‘ x.initializer.run() #增加一个减法sub op, 从‘x‘减去‘a‘,运行减去op,输出结果 sub = tf.sub(x,a) print(sub.eval()) # 任务完成,关闭回话 sess.close()
执行时报错:
Traceback (most recent call last): File "C:/PythonProj/tensorflow/first_tensorflow.py", line 43, in <module> sub = tf.sub(x,a) AttributeError: module ‘tensorflow‘ has no attribute ‘sub‘
经过在pycharm中tf.自动反显的信息,我发现原来这个sub函数已经被subtract代替了,换成tf.subtract(x,a) ,ok ,一切顺利!
2)AttributeError: module ‘tensorflow‘ has no attribute ‘mul‘
input1 = tf.constant(3.0) input2 = tf.constant(2.0) input3 = tf.constant(5.0) intermed = tf.add(input2,input3) mul = tf.mul(input1,intermed) with tf.Session() as sess: result = sess.run([mul,intermed]) print(result)
报错信息为:
Traceback (most recent call last): File "C:/PythonProj/tensorflow/first_tensorflow.py", line 78, in <module> mul = tf.mul(input1,intermed) AttributeError: module ‘tensorflow‘ has no attribute ‘mul‘
同理,经过在pycharm中tf.反显信息的观察,我发现原来这个tf.mul函数已经被换成了tf.multiply了,修改后,ok!
评论(0)