• Python 代码更迭错误简介


    1.

    module 'tensorflow' has no attribute 'placeholder'

    更改:
    import tensorflow as tf


    改为:
    import tensorflow.compat.v1 as tf
    tf.disable_v2_behavior()

    2.

    module 'tensorflow' has no attribute 'random_normal'


    tensorflow 2.0 已经将方法
    random_normal 修改为 random.normal

    3.

    name 'X' is not defined

    原因: X是前面函数的变量,这里没有重新对他们进行定义,就会出现标题所示的问题.
    解决:在X第一次出现的的地方(比如在上一个函数里),用python自带的global函数把他们变成全局变量。
    global X

    4.

     module 'tensorflow._api.v2.train' has no attribute 'GradientDescentOptimizer'

    解决方法:
    optimizer = tf.train.GradientDescentOptimizer

    改为:

    optimizer = tf.compat.v1.train.GradientDescentOptimizer

    5.

    module 'tensorflow' has no attribute 'Session'

    tf.Session()

    改为:

    tf.compat.v1.Session()

    在如上修改之后可能出现的问题

    The Session graph is empty. Add operations to the graph before calling run()

    添加如下代码:

    import tensorflow as tf
    
    tf.compat.v1.disable_eager_execution()

    6.

    module 'tensorboard.summary._tf.summary' has no attribute 'FileWriter'

    tf.summary.FileWriter()

    替换为

    tf.summary.create_file_writer()
    7.module 'tensorflow' has no attribute 'get_default_graph'

    解决方法

    import keras
    或者
     from keras import layers

    改为
    from tensorflow import keras
    或者
    
    from tensorflow.keras import layers
    8.



  • 相关阅读:
    解决小程序sessionid不一致
    小程序实现写入缓存与读取缓存
    小程序登录时如何获取input框中的内容
    js实现截取字符串后几位
    js用正则判断身份证号码
    sublime Text3安装及配置与解决安装插件失败
    jQuery实现全选与全部选
    jQuery实现enter键登录
    常用正则表达式的判断与写法
    js实现正则判断手机号
  • 原文地址:https://www.cnblogs.com/cxy0210/p/14585947.html
Copyright © 2020-2023  润新知