9951 explained code solutions for 126 technologies


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:

  1. import os: This imports the os module, which provides functions for interacting with the operating system.
  2. os.environ["CUDA_VISIBLE_DEVICES"] = "": This sets the CUDA_VISIBLE_DEVICES environment variable to an empty string. This will cause Tensorflow to ignore any GPUs present on the system and run on the CPU.

Helpful links

Edit this code on GitHub