5

I have a running installation of Keras & Theano on Windows (by following this tutorial). Now I've tried to switch the backend to Tensorflow which worked quite fine.

The only issue I have, is that Tensorflow does not detect my GPU, which Theano in contrast does:

from tensorflow.python.client import device_lib
def get_available_gpus():
    local_device_protos = device_lib.list_local_devices()
    return [x.name for x in local_device_protos if x.device_type == 'GPU']

yields no results but when running with Theano backend, it works quite nicely:

C:\Programming\Anaconda3\python.exe D:/cnn_classify_cifar10.py 
Using Theano backend.
DEBUG: nvcc STDOUT nvcc warning : The 'compute_20', 'sm_20', and 'sm_21' architectures are deprecated, and may be removed in a future release (Use -Wno-deprecated-gpu-targets to suppress warning).
mod.cu
    Creating library C:/Users/Alex/AppData/Local/Theano/compiledir_Windows-10-10.0.14393-SP0-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-3.5.2-64/tmpgsy496fe/m91973e5c136ea49268a916ff971b7377.lib and object C:/Users/Alex/AppData/Local/Theano/compiledir_Windows-10-10.0.14393-SP0-Intel64_Family_6_Model_60_Stepping_3_GenuineIntel-3.5.2-64/tmpgsy496fe/m91973e5c136ea49268a916ff971b7377.exp

Using gpu device 0: GeForce GTX 770 (CNMeM is enabled with initial size: 80.0% of memory, cuDNN 5005)

Apparently there is some configuration missing, but I don't know what. For Theano to run correctly, I needed a file called ~/.theanorc with the following content:

[global]
device = gpu
floatX = float32

[cuda]
root = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v8.0

[nvcc]
flags=-LC:C:\Programming\WinPython-64bit-3.5.2.2\python-3.5.2.amd64\libs

Maybe something similar is missing or maybe I need to add environment variables like for Theano?. Possibly related question on Linux (?).

The full installation log (which included a strange exception) can be found in this Gist.

Any ideas, how to make the GPU visible to Tensorflow?

Alexander Pacha
  • 9,187
  • 3
  • 68
  • 108
  • How did you install tensorflow? – Steven Feb 26 '17 at 21:41
  • See my [gist file](https://gist.github.com/apacha/a595c244f90a27aced56f67f7598d90d), using pip install tensorflow and alternatively with the direct url to the wheel. – Alexander Pacha Feb 26 '17 at 21:45
  • The command is wrong. You need to do pip3 install --upgrade tensorflow-gpu – Steven Feb 26 '17 at 21:48
  • 1
    Nope, see this [Gist](https://gist.github.com/apacha/c51ddc00d9c550a68b1208b0a8d7d424). And why should it? I don't have any Python 2.x installation on my machine. – Alexander Pacha Feb 26 '17 at 21:52
  • My issue wasn't with using pip vs pip3 it was with using tensorflow vs tensorflow-gpu. I'm not sure the order of precedence if both are installed on your computer. I think you should uninstall tensorflow and only have installed tensorflow-gpu. – Steven Feb 26 '17 at 21:59
  • Right! That fixed it. Write an answer and I will accept it. – Alexander Pacha Feb 26 '17 at 22:06
  • I think the provided answer is correct, please accept for more visibility – dashesy Jul 06 '17 at 21:18

1 Answers1

5

Installing both tensorflow and tensorflow-gpu on the same machine might cause issues at the moment.

Install either tensorflow (for cpu only) or tensorflow-gpu (for gpu only) for version 1.0

Steven
  • 5,134
  • 2
  • 27
  • 38
  • Huh! It took more googling to find this answer. They seem to overwrite some `pyd` files without any complaints. Why is this little fact not documented? One thinks tensorflow-gpu is an addition to tensorflow and not a substitute. – dashesy Jul 06 '17 at 21:16
  • I don't have a good answer for why they made it so you can't just install both at the moment or even why their documentation is poor. I tried a pull request before about documentation (about something) but after months I just closed it because the actual functionality was going to change in a later version. – Steven Jul 06 '17 at 22:02