Python Machine Learning

Deactivate GPU in machine learning with TensorFlow or Keras

2019-08-24

Share this for your friends.

Deactivate GPU in machine learning with TensorFlow or Keras

Deactivate GPU in machine learning with TensorFlow or Keras.
When our machine learning code does not run, we may estimate program bugs.
Sometimes it is caused by library version unmatch with GPU.
So today I share how to deactivate GPU and run your code with CPU.


Deactivate GPU

In order to deactivate GPU on Python, you can prohibit CUDA to use device by writing it in environment variables.
You can write below before importing Keras.

Then Python can't use GPU and run code with CPU.

import os
os.environ["CUDA_VISIBLE_DEVICES"] = "-1"
import keras

Set environment variables before importing Keras.
How to deactivate GPU when you use Keras on Jupyter


Finally

  • If you want to deactivate GPU in Python, set environment variables



Share this for your friends.

If you felt this article is useful, please share.

にほんブログ村 IT技術ブログへ

-Python, Machine Learning
-

© 2024 ITips