python-tensorflowHow do I disable the GPU in Python Tensorflow?
To disable the GPU in Python Tensorflow, you need to set the CUDA_VISIBLE_DEVICES environment variable to an empty string. This can be done using the following code:
import os
os.environ["CUDA_VISIBLE_DEVICES"] = ""
This will disable the GPU and cause Tensorflow to run on the CPU.
The code consists of two parts:
import os: This imports theosmodule, which provides functions for interacting with the operating system.os.environ["CUDA_VISIBLE_DEVICES"] = "": This sets theCUDA_VISIBLE_DEVICESenvironment variable to an empty string. This will cause Tensorflow to ignore any GPUs present on the system and run on the CPU.
Helpful links
More of Python Tensorflow
- How can I use Tensorflow 1.x with Python 3.8?
- How can I disable warnings in Python TensorFlow?
- How can I use XGBoost, Python, and Tensorflow together for software development?
- How do I resolve the "no module named 'tensorflow.python.keras.preprocessing'" error?
- How can I use Python and TensorFlow to detect images?
- How do I use Python and TensorFlow to fit a model?
- How do I convert an unrecognized type class 'tensorflow.python.framework.ops.eagertensor' to JSON?
- How can I enable GPU support for TensorFlow in Python?
- How can I install and use TensorFlow on a Windows machine using Python?
See more codes...