python - ImportError:无法从“tensorflow”导入名称“Session”
问题描述
我正在努力运行模块。
from tensorflow import Session, ConfigProto, GPUOptions
gpuoptions = GPUOptions(allow_growth=True)
session = Session(config=ConfigProto(gpu_options=gpuoptions))
K.set_session(session)
classifier = Sequential()
我不知道为什么它不起作用。
它只是告诉我:
ImportError: cannot import name 'Session' from 'tensorflow' (C:\Users\hayou\AppData\Local\Programs\Python\Python37\lib\site-packages\tensorflow\__init__.py)
解决方案
我猜你使用的是 TensorFlow 2.x。在这种情况下,请改用 tf.compat.v1.--function--() 。
import tensorflow as tf
gpuoptions = tf.compat.v1.GPUOptions(allow_growth=True)
session = tf.compat.v1.Session(config=tf.compat.v1.ConfigProto(gpu_options=gpuoptions))
K.set_session(session)
classifier = Sequential()
推荐阅读
- excel - VLOOKUP 不适用于通过 VBA 的所有行
- c# - FlowListView 不使用 Observable 更新 Ui
- javascript - 解构 res.headers
- reactjs - 很难在 Android 中选择 TextInput 条目
- javascript - 针对 iPad 的媒体查询
- spring - 使用具体实现时 @JsonTypeInfo 对 REST 端点的影响
- python - 我是 django 的新手,当我尝试 python manage.py runserver 时...我在下面收到错误...我现在必须做什么?请告诉我
- ios - 使用 Snpkit 为这两个控件设置动画。结果,一个控件执行动画,而另一个不移动
- android - HeapTaskDaemon 阻止了 ANR。其他线程似乎处于等待状态
- javascript - 如何从节点 js 中的 RSA 公钥生成 SKI?