zoukankan      html  css  js  c++  java
  • tensorflow官方文档中的sub 和mul中的函数已经在API中改名了

    在照着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!

  • 相关阅读:
    2016012053小学四则运算练习软件项目报告
    读《构建之法》后的思考
    我与软件
    关于结对项目中网页字体的教程
    结对项目
    小学四则运算练习软件项目报告
    2016012028 赵莉 散列函数的应用及其安全性
    2016012028+四则运算练习软件项目报告(结对项目)
    《构建之法》阅读与思考——四、十七章
    2016012028+小学四则运算练习软件项目报告
  • 原文地址:https://www.cnblogs.com/jasmine-Jobs/p/7257070.html
Copyright © 2011-2022 走看看