如何在没有 GPU 的情况下运行 TensorFlow?

use*_*312 4 python gpu keras tensorflow

我的系统有一个 GPU。

当我在其上运行 Tensorflow 时,TF 会自动检测 GPU 并开始在 GPU 上运行线程。

我怎样才能改变这个?

即如何在没有 GPU 的情况下运行 Tensorflow?

Joy*_*dal 5

它应该有效。主要是禁用CUDA设备。因此,代码会寻找其他来源(CPU)来运行代码。

import os
import tensorflow as tf
#os.environ["CUDA_DEVICE_ORDER"]="PCI_BUS_ID" #If the line below doesn't work, uncomment this line (make sure to comment the line below); it should help.
os.environ['CUDA_VISIBLE_DEVICES'] = '-1'
#Your Code Here
Run Code Online (Sandbox Code Playgroud)