How-to setup GPU Accelerated TensorFlow & Keras on Windows 10 with Anaconda 3

Dr. Martin Berger
3 min readMay 2, 2020

--

Photo by Greg Rakozy on Unsplash

In this post I share my beginners experience of how-to setup TensorFlow with Keras utilizing the GPU for computation on Windows 10. My specific goal was to find the simplest way to install these deep learning frameworks.

Environment of my setup

I use the below environment for my setup:

  • Operating System: Windows 10 Home Edition
  • GPU: NVIDIA GeForce GTX 970
  • RAM: 16GB
  • CPU: Intel i7–3770K @ 3.50GHz

Setting up Anacoda 3 as backend for TensorFlow

Anaconda is an open-source distribution of Python and R programming language packages for scientific computing with specific focus on a simple package management and deployment. It ships with Anaconda Navigator, the graphical user interface (GUI) to interact with Anaconda without using a command-line.

Download Anaconda 3 Individual Edition from here and follow the usual Windows installation steps:

Download section of Anaconda 3.

I downloaded and installed Anaconda for Windows 64-bit and Python 3.7.

Setting up a TensorFlow & Keras environment with Anaconda Navigator

Anaconda Navigator GUI with highlighted steps to set up a TensorFlow & Keras environment

Start Anaconda Navigator GUI and proceed with the following steps:

  1. Go to the tab Environments.
  2. Create a new environment, I called it tf-keras-gpu-test. Make sure to select Python 3.6 here as I experienced problems with Python 3.7.
  3. Select Not-installed packages.
  4. Search for tensorflow.
  5. Select packages for TensorFlow and Keras. The highlighted packages selected are for TensorFlow version 2.1.0 and Keras version 2.3.1.
  6. Press Apply button. The installation and configuration of the selected packages will take several minutes.

The Anaconda-managed installation will fetch GPU relevant packages for GPU computation and deep learning with TensorFlow in the background, i.e. CUDA Toolkit 10.2 and NVIDIA CUDA Deep Neural Network library (cuDNN) in version 7.2.

Photo by Nicolas Thomas on Unsplash

Validation of installation

By pressing the play button highlighted besides the selected environment, we can open a Python terminal for the selected environment. By executing the following Python commands we can check the installed TensorFlow and Keras versions:

import tensorflow as tf
tf.__version__
import keras
keras.__version__

These commands in the Python terminal should bring up version 2.1.0 for TensorFlow and version 2.3.1 for Keras. To check if TensorFlow is now able to utilize CPU and/or GPU, execute the following commands:

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

These commands in the Python terminal should bring up both a CPU and a GPU device, if TensorFlow correctly identifies your GPU.

See the output of my Python shell below:

Output of the commands above on the Python terminal
Photo by Alex on Unsplash

Conclusion

My initial worry, the installation of TensorFlow and Keras with GPU computation will get tricky, did not come true! :-)

Thanks to Anaconda 3 powerful package management, the installation was fairly easy and thanks to Anaconda Navigator, it did not involve any command-line commands.

Acknowledgements:

Thanks to Medium authors Ankit Bhatia for this article and Ekapope Viriyakovithya for this article, they brought me on the right and simple track!

--

--