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?

10
  • 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. Commented Mar 22, 2018 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 :) Commented Mar 22, 2018 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? Commented Mar 22, 2018 at 15:29
  • 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. tensorflow.org/install/install_linux#gpu_support Commented Mar 22, 2018 at 15:38
  • 5
    You should uninstall both versions (CPU & GPU), then re-install the GPU version - see answer here Commented Mar 22, 2018 at 15:42

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

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.