Keras: Installing keras makes tensorflow can't find GPU

Created on 15 Mar 2017  路  5Comments  路  Source: keras-team/keras

I have used keras + tensorflow-gpu in my old computer, it's very ok. (I forget the tensorflow version)

I install keras with tensorflow-gpu (version 1.0.1) in my new computer, and before install keras, tensorflow can find my GPU. But after install keras, tensorflow only can find CPU.
(use $ pip3 install keras)

I use these code to check GPU:

from tensorflow.python.client import device_lib
device_lib.list_local_devices() 
$ nvidia-smi



md5-28171dfab9dcda65dd884147ce9b7bb5



...
Installed /home/thisray/keras-test/lib/python3.5/site-packages/Keras-2.0.0-py3.5.egg
Processing dependencies for Keras==2.0.0
Searching for tensorflow
Reading https://pypi.python.org/simple/tensorflow/
No local packages or working download links found for tensorflow
error: Could not find suitable distribution for Requirement.parse('tensorflow')

Is this problem about version ?

thanks

Most helpful comment

Thanks for your explanation.
After: install tensorflow -> install keras -> uninstall tensorflow -> install tensorflow
and it works! Thanks a lot!

All 5 comments

Yeah, currently when you install Keras using pip or pip3 it blows off existing TF and installs the default, non-GPU version. It'd be great if there was a flag to not touch existing TF.

The workaround is to uninstall TF after installing Keras, and then installing the GPU version using pip or pip3 depending on your preferred python version. Not very elegant, but you gotta do what you gotta do.

Argument in favor of more sophisticated handling: some folks use TF they have compiled themselves for their native machine architecture to speed up things like on-CPU image processing. For them to be reset to default TF when they upgrade is a bit of a nuisance.

Thanks for your explanation.
After: install tensorflow -> install keras -> uninstall tensorflow -> install tensorflow
and it works! Thanks a lot!

Thank you very much!
install tensorflow -> install keras -> uninstall tensorflow -> install tensorflow

It worked for me

conda create -n ta  anaconda python
source activate ta
conda install tensorflow-gpu==1.11 cudatoolkit==9.0 cudnn==7.1.2 h5py
pip install pillow h5py keras
pip uninstall tensorflow
pip install tensorflow-gpu

python
import keras.backend as K;[x.name for x in K.get_session().list_devices()]
exit()

git clone https://github.com/fchollet/keras.git
cd keras/examples
python mnist_cnn.py

here is results:

2019-01-09 15:38:30.636492: I tensorflow/core/common_runtime/gpu/gpu_device.cc:988]      0 1 2 3 
2019-01-09 15:38:30.636499: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 0:   N Y N N 
2019-01-09 15:38:30.636504: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 1:   Y N N N 
2019-01-09 15:38:30.636508: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 2:   N N N Y 
2019-01-09 15:38:30.636512: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1001] 3:   N N Y N 
2019-01-09 15:38:30.637425: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10405 MB memory) -> physical GPU (device: 0, name: GeForce GTX 1080 Ti, pci bus id: 0000:02:00.0, compute capability: 6.1)
2019-01-09 15:38:30.638060: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:1 with 10405 MB memory) -> physical GPU (device: 1, name: GeForce GTX 1080 Ti, pci bus id: 0000:03:00.0, compute capability: 6.1)
2019-01-09 15:38:30.638372: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:2 with 10405 MB memory) -> physical GPU (device: 2, name: GeForce GTX 1080 Ti, pci bus id: 0000:82:00.0, compute capability: 6.1)
2019-01-09 15:38:30.638638: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:3 with 10405 MB memory) -> physical GPU (device: 3, name: GeForce GTX 1080 Ti, pci bus id: 0000:83:00.0, compute capability: 6.1)
['/job:localhost/replica:0/task:0/device:CPU:0', '/job:localhost/replica:0/task:0/device:XLA_GPU:0', '/job:localhost/replica:0/task:0/device:XLA_CPU:0', '/job:localhost/replica:0/task:0/device:GPU:0', '/job:localhost/replica:0/task:0/device:GPU:1', '/job:localhost/replica:0/task:0/device:GPU:2', '/job:localhost/replica:0/task:0/device:GPU:3']
Was this page helpful?
0 / 5 - 0 ratings

Related issues

farizrahman4u picture farizrahman4u  路  3Comments

amityaffliction picture amityaffliction  路  3Comments

snakeztc picture snakeztc  路  3Comments

KeironO picture KeironO  路  3Comments

Imorton-zd picture Imorton-zd  路  3Comments