当前位置:网站首页>模块TensorFlow中没有Session
模块TensorFlow中没有Session
2022-07-22 09:17:00 【Li.Thor】
模块TensorFlow中没有Session
AttributeError: module ‘tensorflow’ has no attribute ‘Session’
提示:TensorFlow中没有模块Session;
原因是:我们引用的TensorFlow2.0版本,此版本与1.0相比没有模块Session。
解决方法:
以之前抄的一段代码为例:
import tensorflow as tf
data1 = tf.constant([[6,6]])
data2 = tf.constant([[2]
,[2]])
data3 = tf.constant([3,3])
data4 = tf.constant([[1,2],
[3,4],
[5,6]])
#print(data4.shape)
#print(data1)
with tf.Session() as sess:
print(sess.run(data1[0])) #打印一行
print(sess.run(data4))
print(sess.run(data4[:,0])) #打印第零列
print(sess.run(data4[0,1]))
print(sess.run(data4[0])) #打印第O行
方法一:
将import tensorflow as tf替换成
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
方法二:
将with tf.Session() as sess:替换成
sess = tf.compat.v1.Session()
案例:
#sess = tf.compat.v1.Session()的用法
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
#import tensorflow as tf
data1 = tf.constant([[6,6]])
data2 = tf.constant([[2]
,[2]])
data3 = tf.constant([3,3])
data4 = tf.constant([[1,2],
[3,4],
[5,6]])
with tf.Session() as sess:
print(sess.run(data1[0]))#打印一行
print(sess.run(data4))
print(sess.run(data4[:,0]))#打印第零列
print(sess.run(data4[0,1]))
print(sess.run(data4[0]))#打印第O行
声明:学习中的笔记总结,欢迎交流指点。
边栏推荐
- 05.迪米特原则(Law of Demeter LoD)
- NRF24L01无线模块设置发射接受模式方法
- PAT乙级1020月饼(注意测点)
- [SDIO] sd2.0 protocol analysis summary (II) -- SD card identification & data transmission process
- 1.QTableWidget插入按钮,灵活删除本行,一列显示行号
- 【Audio】基于STM32 I2S移植WM8978 Audio Codec驱动
- debug glance(by quqi99)
- App移動端測試【6】應用程序(apk)包管理與activity
- Data Lake simple record
- 【STM32】STM32 SDIO SD卡读写测试(二)-- SD_Init之Power On阶段
猜你喜欢
OSI模型,TCP/IP模型
IP, subnet mask, gateway, IPS and IDS
【STM32】STM32 SDIO SD卡读写测试(四)-- SD_Test之Transfer Mode阶段
[SDIO] sd2.0 protocol analysis summary (I) -- Introduction to SD card basic probability
[audio] transplant wm8978 audio codec driver based on STM32 I2S
【FatFs】基于STM32 SD卡移植FatFs文件系统
01.开闭原则 Open-Closed Principle
PHP开发中csrf攻击的简单演示和防范
04. interface aggregation principle
微信公众号网页授权----redirect_uri域名与后台配置不一致,错误码10003 错误
随机推荐
02. Dependency Inversion Principle
【 sdio】 résumé de l'analyse du Protocole sd2.0 (Ⅲ) - - Introduction aux commandes pertinentes de la carte SD
ecshop怎么在本地跑超级慢?
[SDIO] sd2.0 protocol analysis summary (I) -- Introduction to SD card basic probability
Codeforces Round #799 (Div. 4)(8/8)
LeetCode 2039. 网络空闲的时刻
Summary 20220119
web新手区
立即执行函数
堡垒机,DMZ区
Go 内存模型
总结20220213(floyd和dijkstra)
1.通过类似window路径的方式访问json
Wampserver is built to Tencent cloud service. Localhost can access Apache, and the domain name can also access its own IIS server, but the domain name cannot be accessed
this指向问题
LeetCode: 627. 变更性别
QT的sprintf重写;qt下内容按界面的缩放而缩放(不改变字体大小)
uniapp 微信小程序地图,在高德app、腾讯app、百度app、苹果地图app 中打开
04. interface aggregation principle
【SDIO】SDIO、SD卡、FatFs文件系统相关文章索引