Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keras does not use GPU - how to troubleshoot?

I'm trying to train a Keras model on the GPU, with Tensorflow as backend.

I have set everything up according to https://www.tensorflow.org/install/install_windows. This is my setup:

  • I'm working in a Jupyter notebook in a virtualenv environment.
  • The current virtualenv environment has tensorflow-gpu installed.
  • I have CUDA 9.1 and cudaDNN for CUDA 9.1 installed.
  • cuDNN64_7.dll is at a location which is accessible via the PATH variable.
  • I have an NVIDIA GeForce GTX 780 on my computer with the latest drivers.

However, Tensorflow does not see any usable GPU:

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 5275203639471190827
]

Keras neither:

from keras import backend as K
K.tensorflow_backend._get_available_gpus()

[]

How can I debug this? How can I find out where the problem is?

like image 757
cheesus Avatar asked May 15 '18 09:05

cheesus


People also ask

How do you check if GPU is being used Keras?

Checking Your GPU Availability With Keras The easiest way to check if you have access to GPUs is to call tf. config. experimental. list_physical_devices('GPU').

Does Keras automatically use GPU?

If your system has an NVIDIA® GPU and you have the GPU version of TensorFlow installed then your Keras code will automatically run on the GPU.

Why is TensorFlow not using GPU?

If TensorFlow doesn't detect your GPU, it will default to the CPU, which means when doing heavy training jobs, these will take a really long time to complete. This is most likely because the CUDA and CuDNN drivers are not being correctly detected in your system.


1 Answers

Check
nvcc -V
and

nvidia-smi

and see if it shows our gpu or not.

Assuming your cuda cudnn and everything checks out, you may just need to
1. Uninstall keras
2. Uninstall tensorflow
3. uninstall tensorflow-gpu
4. Install only tensorflow-gpu pip install tensorflow-gpu==1.5.0
5. Install Keras now.

I followed these steps, and keras now uses gpu.

Hope it helps to some extent.

like image 173
kRazzy R Avatar answered Sep 21 '22 13:09

kRazzy R