版权声明:本文为博主原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。

运行:

import tensorflow as tf
sess=tf.Session(config=tf.ConfigProto(log_device_placement=True))
  • 1
  • 2

出现:

AttributeError: module 'tensorflow' has no attribute 'Session'

原因:
因为是tensorflow 2.0版本

怎么解决:
此时须用

tf.compat.v1.Session()

替代

tf.Session()`

上述代码须为:

import tensorflow as tf
sess=tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(log_device_placement=True))

两个版本tensorflow函数对照:
参考链接:
https://docs.google.com/spreadsheets/d/1FLFJLzg7WNP6JHODX5q8BDgptKafq_slHpnHVbJIteQ/edit#gid=0

AttributeError: module 'tensorflow' has no attribute 'Session'的更多相关文章

  1. AttributeError: module 'tensorflow' has no attribute 'enable_eager_execution'

    Traceback (most recent call last): File "linear_regression_eager_api.py", line 15, in < ...

  2. AttributeError: module 'tensorflow' has no attribute 'sub'

    官方的例子:运行之后出现以下错误 # 进入一个交互式 TensorFlow 会话. import tensorflow as tf sess = tf.InteractiveSession() x = ...

  3. python3 ,AttributeError: module 'tensorflow' has no attribute 'merge_summary'

    error:tensorflow有些方法属性被改了, self.summary_writer = tf.train.SummaryWriter(summary_dir)改为:summary.FileW ...

  4. AttributeError: module 'tensorflow' has no attribute 'set_random_seed'

    anaconda3 python3.7 安装好tensorflow 后出现上面的问题,原因是安装的tensorflow版本是2.0的,所以使用以前的代码tensorflow中的函数不兼容.

  5. 吴裕雄--天生自然 pythonTensorFlow图形数据处理:解决module 'tensorflow' has no attribute 'Session'

    原因:因为是tensorflow 2.0版本

  6. Debug 路漫漫-14:Python: AttributeError: module 'tensorflow' has no attribute 'sub'

    在调试 <Neural Factorization Machines for Sparse Predictive Analytics>论文的源码(https://github.com/he ...

  7. Tensorflow之AttributeError: module 'tensorflow' has no attribute 'mul'

      tf.mul已经在新版本中被移除,请使用 tf.multiply 代替

  8. 【pycharm】pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法

    pycharm上安装tensorflow,报错:AttributeError: module 'pip' has no attribute 'main' 解决方法 解决方法: 在pycharm的安装目 ...

  9. AttributeError: module ‘tensorflow.python.ops.nn’ has no attribute ‘leaky_relu’

    #AttributeError: module 'tensorflow.python.ops.nn' has no attribute 'leaky_relu' 的原因主要是版本的问题 解决方法是更新 ...

随机推荐

  1. ANSI Common lisp1

    lisp(本文专指common lisp)语言简介 lisp程序员能够并且经常编写一些能够写程序的程序,对于程序生成程序的这种特性, 因为lisp是主流语言中唯一一个提供一些方便的抽象来让你完成这个任 ...

  2. libevent笔记3:evbuffer

    evbuffer 之前提到bufferevent结构体提供两个缓存区用来为读写提供缓存,并自动进行IO操作.这两个缓存区是使用Libevent中的evbuffer实现的,同样,Libevent中也提供 ...

  3. kali 破解wifi

    1.查看网卡名称:iwconfig 有一块 名为wlan0 的无线网卡通过一下命令排除影响因素 root@jkali:~# iwconfig lo no wireless extensions. wl ...

  4. Airtest-UI 自动化集大成者

    前言 Airtest是由网易研发的一款基于Python的.跨平台的UI自动化测试框架,基于图像识别原理,适用于游戏和App.该项目目前已在Github上面开源: https://github.com/ ...

  5. CountDownLatch源码

    public class CountDownLatchExample1 { public static void main(String[] args) throws Exception { Exec ...

  6. python mysqldb批量执行语句executemany

    MySQLdb提供了两个执行语句的方法,一个是execute(),另一个是executemany() execute(sql) 可接受一条语句从而执行 executemany(templet,args ...

  7. 给电脑提升权限---- 切换为administrator

    在装系统的时候我们都会在安装的时候进行创建用户这一操作,安装软件的时候总会出现权限不足的情况, 个人建议:如果你要是比较会使用电脑的话,可以体验一下超级管理员这一角色, 就是安装好了之后,切换为超级管 ...

  8. 在Windows 10中禁用自动文件夹类型发现

    点击下载注册表文件:https://files.cnblogs.com/files/Music/win10_automatic_folder_type_discovery.zip 已知Windows ...

  9. Mysql系列(四) —— MySQL的Charset和Collation

    本文转载自:再见乱码:5分钟读懂MySQL字符集设置 一.内容概述 在MySQL的使用过程中,了解字符集.字符序的概念,以及不同设置对数据存储.比较的影响非常重要.不少同学在日常工作中遇到的" ...

  10. drools规则语法(一)

    1.基本的匹配规则 1.1变量 drools使用匹配的方式对Fact进行比对, 比如 account : Account(balance > 100) 这个规则的含义就是在Fact中找到类型为A ...