【发布时间】:2021-04-27 23:07:06
【问题描述】:
我首先在我的 GPU 上使用 python 创建了我的 TensorFlow 代码:
import tensorflow-gpu as tf
我将它用于培训目的,一切都很顺利。但是现在,我想在没有 GPU 的设备上部署我的 python 脚本。所以,我用 pip 卸载了 tensorflow-gpu 并导入了普通的 TensorFlow:
import tensorflow as tf
我试过这段代码:
try:
# Disable all GPUS
tf.config.set_visible_devices([], 'GPU')
visible_devices = tf.config.get_visible_devices()
print(visible_devices)
for device in visible_devices:
assert device.device_type != 'GPU'
except Exception as e:
# Invalid device or cannot modify virtual devices once initialized.
print(e)
但仍然无法正常工作(即使 gpu 似乎已禁用,如屏幕截图中的白色所示)。
我只想返回没有 GPU 功能的默认 TensorFlow 安装。 我尝试卸载并安装 tensorflow,删除虚拟环境并创建一个新环境,但没有任何效果。
感谢您的帮助!
【问题讨论】:
-
这能回答你的问题吗? Prevent TensorFlow from accessing the GPU?
-
不,我没有 CUDA_VISIBLE_DEVICES 环境变量。而且我更愿意安装非 GPU 的 TensorFlow。
-
你看过其他答案吗?比如 .. sess_cpu = tf.Session(config=tf.ConfigProto(device_count={'GPU': 0}))
-
或者,您可以使用带有非 GPU TensorFlow 的 virtualenv。
-
sess_cpu = tf.Session(config=tf.ConfigProto(device_count={'GPU': 0})) 不起作用。它引发:AttributeError:模块'tensorflow'没有属性'Session'
标签: python tensorflow gpu tensorflow2.0 cpu