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.



  • 相关阅读:
    Docker部署nginx
    解决网页在手机端适配问题
    记一次Jenkins+Docker+gitlab自动化部署vue
    Docker部署jenkins
    备案
    Jenkins插件使用--Publish Over SSH
    打开root用户ssh登陆
    gitlab配置git
    Dokcer容器内无法域名解析
    vue开发环境搭建
  • 原文地址:https://www.cnblogs.com/cxy0210/p/14585947.html
Copyright © 2011-2022 走看看