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!

  • 相关阅读:
    前端 JS 原生JS实现一个单页应用的路由 router
    Gitbook 使用笔记
    EF Core 抓取SQL语句
    .NET5.0 MVC Session 的使用
    SQL Server 实用语句
    .NET5.0 MVC 生成发布(问题+技巧)
    服务器 SQL Sserver2012 开启远程连接
    windows 安装 Redis5.0 并运行
    前端 JS 学习笔记(知识点记录)
    CentOS 7 单机安装Redis Cluster(3主3从)
  • 原文地址:https://www.cnblogs.com/jasmine-Jobs/p/7257070.html
Copyright © 2011-2022 走看看