12

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?

2
  • 1
    Have you performed the steps to verify that CUDA and cuDNN were installed correctly, as laid out in their installation manuals? Commented May 15, 2018 at 9:55
  • 1
    Duh, I took CUDA 9.1 instead of CUDA 9.0. Maybe that's the reason. Gonna switch to 9.0 and try again. Commented May 15, 2018 at 9:59

1 Answer 1

17

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Since the answer is now (partially) outdated and I lost over an hour troubleshooting this, I suggest future people with this issue to read carefully the updated tutorial: TensorFlow 2.10 was the last TensorFlow release that supported GPU on native-Windows; so either you pip install "tensorflow<2.11" or you use WSL

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.