Search code examples
pythontensorflowmachine-learningkeras

Keras not detecting GPU, but tensorflow is


I am trying to get my keras back-end to work, but it keeps telling that there is no GPU, but my tensorflow say otherwise.

tensorflow

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

Ouput

[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 7600201089948511065
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 9640434864482537344
physical_device_desc: "device: XLA_CPU device"
, name: "/device:XLA_GPU:0"
device_type: "XLA_GPU"
memory_limit: 17179869184
locality {
}
incarnation: 15836333527683385212
physical_device_desc: "device: XLA_GPU device"
]

keras

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

Output

[]

Tensorflow-gpu works, but keras can't see for some reason

Cuda is installed

tensorflow-gpu = 1.14.0
keras = 2.0.8
python = 3.6

Solution

  • Few things that you need to confirm before this,

    Which GPU are you using? Only NVIDIA works. Do you have tensorflow-gpu installed (keras uses this as its backend)? Do you have CUDA installed?

    Since tensorflow is detecting GPU, then its either an issue with on of the above points, or you may try upgrading the various packages.

    Lastly, if nothing else works I would recommend using the high level API in tensorflow2 which is actually the same as keras.

    Hope this helps.