Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GPU is not used for calculations despite tensorflow-gpu installed

My computer has the following software installed: Anaconda (3), TensorFlow (GPU), and Keras. There are two Anaconda virtual environments - one with TensorFlow for Python 2.7 and one for 3.5, both GPU version, installed according to the TF instructions. (I had a CPU version of TensorFlow installed previously in a separate environment, but I've deleted it.)

When I run the following:

source activate tensorflow-gpu-3.5
python code.py

and check nvidia-smi it shows only 3MiB GPU Memory Usage by Python, so it looks like GPU is not used for calculations. (code.py is a simple deep Q-learning algorithm implemented with Keras)

Any ideas what can be going wrong?

like image 435
Massyanya Avatar asked Dec 06 '25 17:12

Massyanya


1 Answers

TensorFlow on Windows

It took me hours to fix TensorFlow installation issues on windows, so here is summary:

To Check if TensorFlow-gpu is working or not (use this code):

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)
with tf.Session() as sess:
    print(sess.run(c))

To Check list of available CPUs or GPUs (use this code):

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

if tf.test.gpu_device_name():
    print('Default GPU Device: {}'.format(tf.test.gpu_device_name()))
else:
    print("Please install GPU version of TF")

Install Tensorflow GPU on Windows using CUDA and cuDNN

Guide Overview

  • Install Nvidia's card on your computer along with drivers
  • Download & Install CUDA
  • Download & "Install" cuDNN
  • Uninstall Tensorflow, Install Tensorflow GPU
  • Update the %PATH% on the system
  • Verify installation

Guide Complete details

  • install-tensorflow-gpu-windows-cuda-cudnn
  • how-to-install-and-run-gpu-enabled-tensorflow-on-windows

Make Sure

  • You have uninstalled tensorflow and you have installed just tensorflow-gpu in order to get things done.
  • Uninstall tensorflow from pip and conda environement depending upon your project settings and install just tensorflow-gpu
  • After settings PATH variable make sure to logout or reboot your system.

Hope thats helpful :))

like image 62
Aqib Mumtaz Avatar answered Dec 09 '25 17:12

Aqib Mumtaz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!