zoukankan      html  css  js  c++  java
  • 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.



  • 相关阅读:
    MIN (Transact-SQL)【转】
    ROW_NUMBER() OVER函数的基本用法用法【转】
    读取文件中的内容
    Stopwatch 和TimeSpan介绍【转】
    TimeSpan类【转】
    Stopwatch 类【转】
    ToString()使用方法
    用c#读取文件内容中文是乱码的解决方法:
    vue实现购物车和地址选配(二)
    vue实现购物车和地址选配
  • 原文地址:https://www.cnblogs.com/cxy0210/p/14585947.html
Copyright © 2011-2022 走看看