9

I wanted to have gpu-support for keras/tensorflow, thats why I installed tensorflow-gpu. So I installed tensorflow-gpu through pip:

pip install --upgrade tensorflow-gpu

This leads to this:

from keras import backend as K
K.tensorflow_backend._get_available_gpus()
> []

Then I found this stackoverflow answer which stated I should uninstall tensorflow after installing tensorflow-gpu. This leads to this:

Using TensorFlow backend.
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-3d00d838479b> in <module>()
----> 1 from keras import backend as K
      2 K.tensorflow_backend._get_available_gpus()

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/__init__.py in <module>()
      1 from __future__ import absolute_import
      2 
----> 3 from . import utils
      4 from . import activations
      5 from . import applications

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/utils/__init__.py in <module>()
      4 from . import data_utils
      5 from . import io_utils
----> 6 from . import conv_utils
      7 
      8 # Globally-importable utils.

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/utils/conv_utils.py in <module>()
      7 from six.moves import range
      8 import numpy as np
----> 9 from .. import backend as K
     10 
     11 

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/backend/__init__.py in <module>()
     82 elif _BACKEND == 'tensorflow':
     83     sys.stderr.write('Using TensorFlow backend.\n')
---> 84     from .tensorflow_backend import *
     85 else:
     86     raise ValueError('Unknown backend: ' + str(_BACKEND))

/raid/ntzioras/VirtualEnvironments/DeepLearning/lib/python3.4/site-packages/keras/backend/tensorflow_backend.py in <module>()
      4 
      5 import tensorflow as tf
----> 6 from tensorflow.python.training import moving_averages
      7 from tensorflow.python.ops import tensor_array_ops
      8 from tensorflow.python.ops import control_flow_ops

ImportError: No module named 'tensorflow.python'

Reeinstalling tensorflow with

pip install --upgrade tensorflow --no-cache

leads again to an empty array for the gpus with the code above.

Any ideas how to fix this?

greece57
  • 421
  • 1
  • 6
  • 16
  • What is the compute ability of your gpu? I ran into a similar problem and its because they changed the default compute range of the gpu from 3.0 to 3.5. I had to build from source to get mine to work. – Grant Williams Mar 22 '18 at 15:23
  • Actually I dont know. It's a nvidia-dev box setup by another person. I ll have to ask him tomorrow to get more informations but I first wanted to ask here if I run into a common error :) – greece57 Mar 22 '18 at 15:26
  • If its a dedicated box i wouldnt worry about it too much. Its much more likely to be a problem with an older laptop or something similar. You do have Keras installed correct? – Grant Williams Mar 22 '18 at 15:29
  • Keras is working fine but gpus are not detected. I installed keras by: pip install keras; pip install tensorflow-gpu; pip uninstall tensorflow; pip install tensorflow; – greece57 Mar 22 '18 at 15:31
  • Can you run the code from this answer: https://stackoverflow.com/questions/38559755/how-to-get-current-available-gpus-in-tensorflow ? Its probably a good idea to check your CUDA installation as well with `nvcc - V` – Grant Williams Mar 22 '18 at 15:34
  • "'nvcc' is currently not installed". Since I don't have sudo-rights I ll have to wait until tomorrow to try this out. May that solve the problem? The code from the other answer returns also [] for the gpu-list. – greece57 Mar 22 '18 at 15:35
  • 1
    You need to have CUDA installed and setup for the GPU version of tensorflow. Here is the guide for setting up TF with GPUs on linux. The page also has guides for OSX and Windows. https://www.tensorflow.org/install/install_linux#gpu_support – Grant Williams Mar 22 '18 at 15:38
  • 5
    You should uninstall **both** versions (CPU & GPU), then re-install the GPU version - see [answer here](https://stackoverflow.com/questions/46080634/keras-with-tensorflow-backend-not-using-gpu/46095279#46095279) – desertnaut Mar 22 '18 at 15:42
  • @desertnaut this helped and lead to a new error which seam to be related to a wrong/different CUDA Version: ImportError: libcublas.so.9.0: cannot open shared object file: No such file or directory I already found an answer to this: https://github.com/tensorflow/tensorflow/issues/15604 – greece57 Mar 22 '18 at 16:01
  • If the answer was helpful, upvotes are most welcome - χαιρετισμούς ;) – desertnaut Mar 22 '18 at 16:08

1 Answers1

12

This solution worked for me:

Uninstalling both CPU and GPU versions of TensorFlow and then installing only the GPU version of TensorFlow.

pip uninstall tensorflow
pip uninstall tensorflow-gpu

pip install tensorflow-gpu
Safwan
  • 3,300
  • 1
  • 28
  • 33