9
  1. Is there way to check I installed GPU version of Tensorflow?
  2. !nvidia-smi

Mon Dec 18 23:58:01 2017

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 384.90                 Driver Version: 384.90                    |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|===============================+======================+======================|
|   0  GeForce GTX 1070    Off  | 00000000:01:00.0  On |                  N/A |
| N/A   53C    P0    31W /  N/A |   1093MiB /  8105MiB |      0%      Default |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                       GPU Memory |
|  GPU       PID   Type   Process name                             Usage      |
|=============================================================================|
|    0      1068      G   /usr/lib/xorg/Xorg                           599MiB |
|    0      2925      G   compiz                                       290MiB |
|    0      3611      G   ...-token=11A9F5872A56620B72D1D5DF707CF1FC   200MiB |
|    0      5786      G   /usr/bin/nvidia-settings                       0MiB |
+-----------------------------------------------------------------------------+

But when I try to detect the list local devices, only CPU got detected.

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

[name: "/cpu:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 3303842605833347443
]

Do I have to set something else to use the GPU for Keras or Tensorflow?

Bahman_Aries
  • 4,658
  • 6
  • 36
  • 60
kim jake
  • 91
  • 1
  • 1
  • 4

6 Answers6

3

Use pip install tensorflow-gpu or conda install tensorflow-gpu for gpu version of tensorflow. If you are using keras-gpu conda install -c anaconda keras-gpu command will automatically install the tensorflow-gpu version. Before doing these any command make sure that you uninstalled the normal tensorflow .

9113303
  • 852
  • 1
  • 16
  • 30
  • 3
    I have the same problem, but your solutions don't work. Do you have any other suggestion? – Hamed Baziyad Dec 01 '18 at 09:30
  • 1
    As of Tensorflow 2.X `conda install tensorflow` will work for a GPU. source: https://towardsdatascience.com/installing-tensorflow-gpu-in-ubuntu-20-04-4ee3ca4cb75d – Joooeey May 06 '21 at 13:10
1

You may need this shell to config your tensorflow-gpu.

You can run this, if you want to check tensorflow-gpu.

import tensorflow as tf
with tf.device('/gpu:0'):
  a = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[2, 3], name='a')
  b = tf.constant([1.0, 2.0, 3.0, 4.0, 5.0, 6.0], shape=[3, 2], name='b')
  c = tf.matmul(a, b)
sess = tf.Session(config=tf.ConfigProto(log_device_placement=True))
print sess.run(c)

The official documents: Using GPUs.

dxf
  • 573
  • 1
  • 3
  • 9
  • how about keras? – kim jake Dec 19 '17 at 12:43
  • You can look at Keras documentation: [how-can-i-run-keras-on-gpu in keras](https://keras.io/getting-started/faq/#how-can-i-run-keras-on-gpu). I think you should first check if tensorflow-gpu was installed successfully or not. Then try to call it in keras. – dxf Dec 20 '17 at 02:20
  • There is an useful [answer](https://stackoverflow.com/questions/40690598/can-keras-with-tensorflow-backend-be-forced-to-use-cpu-or-gpu-at-will/44833979#44833979) for you. – dxf Dec 20 '17 at 02:31
1

The simple way using tensorflow is:

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

With Keras:

from keras import backend as K
K.tensorflow_backend._get_available_gpus()
Marco Visibelli
  • 359
  • 3
  • 7
0

I have the same problem, but everything was in this page couldn't solve my problem. I decided to update my display adapter. Follow this way:

Control Panel>Device Manager>display adapter>Right click>Update Driver

After that, you must restart your computer, But you should consider that it's not only source of your problem.

Hamed Baziyad
  • 1,954
  • 5
  • 27
  • 40
0

I ran into the subj when using a proper tensorflow-gpu docker container, and using tensorflow-gpu installed into a virtualenv within the container. Most likely this combination properly shields GPU capabilities, which otherwise are available if running python just in the container without virtualenv.

Tosha
  • 998
  • 1
  • 10
  • 22
0

I think that you need to install cuda (it must show up in your nvidia-smi) Did you check compatibility between your cuda/CUDNN version and tensorflow-gpu ? This may help you: https://punndeeplearningblog.com/development/tensorflow-cuda-cudnn-compatibility/

  • 1
    It would be better to include the relevant parts of the post you linked to in your answer. That way, your answer will still be useful in the event that links break. – phalteman Jul 21 '21 at 18:32