我为运行模块而苦恼。
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)
答案 0 :(得分:1)
我猜您正在使用TensorFlow2.x。在这种情况下,请改用tf.compat.v1 .-- function-()。
Remove
答案 1 :(得分:0)
就我而言,我使用的是没有 Session 的 tensorflow v2.2
。但是,它在以前的版本中已经存在,因此您可能需要安装旧版本的 tensorflow,例如 v1.15
,其中包含 Session 类。
pip install tensorflow==1.15
我不确定这是最好的解决方案,但它对我有用,所以我希望它也对你有用!