This article will give you a brief guide over  “How to setup Python Environment for training Deep Learning models in Windows 10?”  I, especially included Windows 10, as some AI enthusiasts has a familiar grip over the Windows OS; like me. But I recommend the similar setup steps to be taken into consideration while in Mac or Ubuntu OS. Just refer official Tensorflow guide for installation process on Windows as well as on various OS.

First of all, for all the beginners here, I’ll guide you through quick steps for python environment setup.
  1. Download Anaconda
  2. Installation of Anaconda
  3. Run and Check the Update for Anaconda
  4. Installation of CUDA Toolkit & cuDNN
  5. Create a Conda Environment
  6. Install Deep Learning Libraries (TensorFlow & Keras)
Before taking these steps, you will need to check your system information from
Control Panel→System and Security→System ie. What is System type? Check whether your Windows system is having 64-Bit or 32-Bit version, in order to download a similar version of Anaconda(Python).
Also, check whether your machine supports Intel/Nvidia graphics card (GPU) or not. Because processing power of GPU is higher than CPU so that we can install Tensorflow for GPU and not for CPU. But in this guide, I’ll show for both CPU and GPU support. Check whether your system has powerful GPU ie. Nvidia graphics card, by typing Windows icon button + R. Then type dxdiag and run. Click on display and render options, check whether your machine is compatible with any Nvidia GPU version or has only Intel supported the graphics card. Nvidia graphics card is must for installing Tensorflow for GPU.

In my case, my machine has integrated graphics card, I have Nvidia GeForce 940MX Graphic card in my render option. So I can able to install Tensorflow (for GPU).

STEP 1: Download Anaconda (Python)

Download Anaconda for Python: Anaconda – Windows system.
From under Python 3.6 version, choose either 64-Bit or 32-Bit as per your system type. As Python 3.6 version is compatible for working on the Tensorflow library. You can go for the Python 2.7 version, if you just want to train machine learning models and not the complex deep learning model which needs high computational power.

STEP 2: Installation of Anaconda
While installing just click next and go further with default options. Complete Installation process may take upto 10mins or less as per your system.

Suppose, if you got confused for the below installation procedure, please read the NOTE.

NOTE: Select the first option if you want to run the conda also in the cmd ie. system’s command prompt. Otherwise, don’t select the first option; as the default is Anaconda prompt to run the conda, python scripts and tensorflow library. I recommend not to select the first option, just select the second option and click install. If needed, we can edit environmental variables later to add Anaconda to the system path.

Command Prompt not recognising the conda list, python and jupyter notebook.

In future, if you want to run the conda also in the cmd, you will need to add the path of conda and python by editing the system environment variables, so as to get recognised by the system’s command prompt.
After the Installation gets completed, just search Anaconda Prompt in the system search bar and click it and the Anaconda Prompt starts.

Find out the path of conda and python from Anaconda Prompt:

Add the below paths to environment variables, to run conda in cmd.

STEP 3: Run and Check the Update for Anaconda

Run the commands – conda list, python and jupyter notebook in Anaconda Prompt as shown in the fig.

conda install jupyter
My jupyter notebook was already installed!

jupyter notebook

The conda and python commands are working that means their path is saved sucessfully and now we are ready to update python libraries. 
Jupyter notebook opens in a default browser.
Anaconda navigator comes along with the installation, which contains several python related applications and environments supported by the Anaconda Community.

Open a new Anaconda Prompt. And update the conda:

conda update conda
conda update --all

Installation process for Tensorflow with CPU support only: (In either cmd or anaconda prompt)

If you didn’t have Nvidia Graphics card with GPU support, you can proceed to the below given some commands; in order to install tensorflow with CPU support. 

Install some basic python packages which requires for machine learning purpose:

conda install scipy
pip install sklearn
pip install pandas
pip install pandas-datareader
pip install matplotlib
pip install pillow
pip install requests
pip install h5py
pip install --upgrade tensorflow

Now run the sample tensorflow code in either python shell by typing “idle” in the Anaconda Prompt or  by calling “jupyter notebook”.

import tensorflow as tf
hello = tf.constant('Hello, TensorFlow!')
sess = tf.Session()

To install Tensorflow with GPU support:

Make sure you have C++ compiler installed in your machine separately. Or download Microsoft Visual Studio Community Edition in which C++ compiler comes by default, as a supporter for various applications.

Download Microsoft Visual Studio:

I’ve downloaded and installed Microsoft Visual Studio 2015 Community Edition which comes with the default C++ compiler support. We require this for installation of CUDA toolkit and setting up the cuDNN.

STEP 4: Installation of CUDA Tookit & cuDNN

For CUDA Toolkit:

Check which CUDA version is capable for your GPU for installation. I’ve downloaded CUDA Toolkit 9.0 for my Windows 10 machine. First, download the base installer and then download the latest patch. Overall CUDA toolkit Installation process may take upto 10mins.

To know more about system requirements, just read the CUDA Toolkit Documentation.

After CUDA Toolkit installation, make sure to update Nvidia Graphic Drivers. Join as the Nvidia developer by setting up an account. Then search for your Nvidia GPU’s drivers for download.
In my case, my system has Nvidia GEFORCE support.

For cuDNN:

NVIDIA cuDNN is a GPU-accelerated library of primitives for deep neural networks.
Download cuDNN
In order to download cuDNN, ensure you are registered for the NVIDIA Developer Program.

Go to: NVIDIA cuDNN home page. Click Download. Complete the short survey and click Submit. Do accept the Terms and Conditions. A list of available download versions of cuDNN displays.

As per my system’s GPU requirement, I’ve downloaded cuDNN v7.1.4 (May 16, 2018), for CUDA 9.0 ie. cuDNN v7.1.4 Library for Windows 10. You choose cuDNN version as per your system’s requirement. It gets downloaded in the .zip formate. Paste the .zip in the Windows(C) path and extract it into the folder.

STEP 5: Create an conda Environment

Before commanding on prompt; you need to copy the bin, include and lib folders of the cuDNN unzipped folder. And paste it under the CUDA’s path (ie.C:Program FilesNVIDIA GPU Computing ToolkitCUDAv9.0) by replacing on CUDA’s bin, include and lib folders.

Now you’ll need to create an conda Environment for Tensorflow (GPU) in Anaconda Prompt.

conda create -n tensorflow
activate tensorflow
(tensorflow)C:>  # Your prompt should change like this.

STEP 6: Install Deep Learning Libraries (TensorFlow & Keras)

After activating the tensorflow environment, we will move for the installation process. And we will see the working of some popular libraries known as Tensorflow and keras.

Run the below commands, under python shell in the current activated tensorflow environment.

pip install tensorflow-gpu
pip install --ignore-installed --upgrade tensorflow-gpu

Install Keras only after the tensorflow installation. As the tensorflow works as a background process and Keras runs over it.

pip install keras

To check whether tensorflow running on GPU or on CPU.

from tensorflow.python.client import device_lib 
It is showing device type: GPU ie. Tensorflow is working with GPU support too.

Now check whether the tensorflow works with GPU support, by running a simple ” Hello Tensorflow “code.

Leave a Reply

Your email address will not be published.