Python Environment Setup for Deep Learning on Windows 10 | by Tamim Mirza | Towards Data Science

A detailed introduction on how to get started with Deep Learning starting with enabling an environment suited to it on the Microsoft Windows 10. The frameworks to be installed will be Keras API with Google’s TensorFlow GPU version as the back end engine.
This guide is the same procedure I had utilized during my own deep learning project and it has served me well. The purpose of this guide is to accumulate all necessary and updated information in one place rather than searching all over Google.
Let’s get started.
This guide has been updated to the release of TensorFlow 2.1
What is Deep Learning?PC Hardware SetupPC Software SetupPython InterpreterPython IDE
What is Deep Learning?
PC Hardware Setup
PC Software Setup
Python Interpreter
Python IDE
Deep learning is a subset of machine learning that utilizes multi-layered artificial neural networks to deliver state-of-the-art accuracy in tasks such as object detection, speech recognition, language translation and others.
Deep learning differs from traditional machine learning techniques in that they can automatically learn representations from data such as images, video or text, without introducing hand-coded rules or human domain knowledge. Their highly flexible architectures can learn directly from raw data and can increase their predictive accuracy when provided with more data.
To perform deep learning on any data set, the software/program requires a computer system powerful enough to handle the computing power necessary. So the following minimum specs are required:
1) Central Processing Unit (CPU) — Intel Core i5 6th Generation processor or higher. An AMD equivalent processor will also be optimal.
2) RAM — 8 GB minimum, 16 GB or higher is recommended.
3) Graphics Processing Unit (GPU) — NVIDIA GeForce GTX 940 or higher. AMD GPUs are not able to perform deep learning regardless.
NVIDIA CUDA-enabled GPUs for deep learning
4) Operating System — Microsoft Windows 10 (64-bit recommended) Pro or Home. I recommend updating Windows 10 to the latest version before proceeding forward.
Note: In case of laptops, the ideal option would be to purchase a gaming laptop from any vendor deemed suitable such as ASUS, Lenovo Legion, Acer Predator, Alienware, etc.
Now to perform deep learning we are going to use a method known as GPU computing which directs complex mathematical computations to the GPU rather than the CPU which significantly reduces the overall computation time. To do so we install several components in the following order:
Visual Studio is crucial for the installation of the next two components. I recommend Visual Studio 2019 (since I use it) as its performance supersedes all of it’s predecessors and installation has never been easier nor faster than ever before. But there is a range that you can use any VS version from 2012 to 2019.
Download Visual Studio 2019
Download Visual Studio 2017 and older
If you have Visual Studio 2019 installed then you have to update it to version 16.4 or higher. New installations of VS 2019 are updated by default.
After installing Visual Studio 2019 (or 2017 as it is similar to 2019) then please ensure that “Desktop Development with C++” workload is installed along with the following components:
MSVC v142 — VS 2019 C++ x64/x86 build tools (v14.24)Windows 10 SDK (Any version)
MSVC v142 — VS 2019 C++ x64/x86 build tools (v14.24)
Windows 10 SDK (Any version)
This tool is designed to update your NVIDIA GPU drivers and it is far easier to do it like this and it is highly recommended to be installed if you have an NVIDIA GPU
Download NVIDIA GeForce Experience
Install it and you will need to create an account in order to use it. You should see a screen like this
In the red box you can see a button labeled “Check for Updates”. The automatic update function is not reliable so manually check for updates before proceeding to download the next software.
If your driver is updated then great you can move on. If not then please update it although CUDA Toolkit comes bundled with drivers but it is recommended to do it from here as they only carry the minimum drivers requirement at the time of release (since its possible you are using this a certain time after the release date).
This software component is what is required to enable the GPU to be capable for GPU computing. We will download version 10.0 as that is the compatible version with the frameworks that we will be installing.
Note: TensorFlow 2.1 is compatible with CUDA Toolkit 10.1 only.
Download CUDA Toolkit 10.1
Official Windows Installation Documentation for CUDA 10.1
Next you need to go into the samples folder in your CUDA installation where it, if you chose the default path during installation, is at:
C:\ProgramData\NVIDIA Corporation\CUDA Samples\v10.1\1_Utilities\deviceQuery
and select the VS Solution appropriate to the VS version installed on your system and run it on your installed version of Visual Studio. If you have Visual Studio 2017 then run the Visual Studio solution for VS 2017. At the of the result from running the solution you should have attained
With the installation verified you need to add CUDA Toolkit to the Path environment which is done through the following method:
Step #1
Step #2
Step #3
Step #4
Step #5
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\binC:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include
Download NVIDIA cuDNN
You need to sign up for an NVIDIA Developer account in order to download it which is free and not that much a bother. Download cuDNN 7.6.X for CUDA 10.1.
Once downloaded, unzip it and you will have 3 files and then do:
a) Copy <installpath>\cuda\bin\cudnn64_7.dll to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\bin.
b) Copy <installpath>\cuda\ include\cudnn.h to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\include.
c) Copy <installpath>\cuda\lib\x64\cudnn.lib to C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.1\lib\x64.
Once completed your GPU is now ready to perform GPU computing.
Now that we have our GPU configured, it is time to install our python interpreter which we will go with Anaconda. It is deemed far better to use than the traditional python installation and will operate much better.
There are two variations of this interpreter that we can install called Anaconda and Miniconda. To choose which one to go with refer the following guide (taken from official documentation):
Choose Anaconda if you:
Are new to conda or Python
Like the convenience of having Python and over 150 scientific packages automatically installed at once
Have the time and disk space (a few minutes and 5 GB), and/or
Don’t want to install each of the packages you want to use individually.
Choose Miniconda if you:
Do not mind installing each of the packages you want to use individually.
Do not have time or disk space to install over 150 packages at once, and/or
Just want fast access to Python and the conda commands, and wish to sort out the other programs later.
I use Miniconda myself. Anaconda is bloated. Many of the packages are never used and could still be easily installed if and when needed.
Note: It is recommended (but not necessary) to download the Python 3 versions of your choice interpreter since Python 2 is reaching it’s end-of-life.
Click to download Anaconda
Click to download Miniconda
Once you have installed your choice interpreter, it time to install the required packages. Open Anaconda Prompt and type in the command:
conda update conda
For Anaconda-only users, after you type in the above command, next type in:
conda update anaconda
Do NOT close Anaconda prompt just yet.
Note: TensorFlow supports Python 3.5, 3.6 and 3.7 on Windows 10. Although TensorFlow 2.1 will be the final version of TensorFlow that will support Python 2 (regardless of OS).
Now it is time to create our environment, we can do this through Anaconda Prompt easily (in this case we will be creating a Python 3.7 environment named TensorFlow-GPU):
conda create -n TensorFlow-GPU python=3.7
And we have successfully created the new environment.
Do NOT close Anaconda prompt just yet.
Now we begin to installed tensorflow GPU version and to do that we first activate our newly created environment. Simply type in:
conda activate TensorFlow-GPU
Next we install TensorFlow 2.1 (The base package tensorflow already contains support for CPU and GPU and will configure according to the system):
pip install tensorflow
The pip version is officially supported while the conda version is community supported. Google recommends to install the pip version.
TensorFlow version 1.13 and onwards come with Keras pre-installed and built with TensorFlow and so it exempts the users from installing a separate Keras package.
Now to test the environment, invoke the command:
python
Then type in:
>>import tensorflow as tf
If this is the result you get:
>>import tensorflow as tf>>
Then it means that the installation was successful. Now we move on to the IDE. You may close the prompt.
Both of the following are great in debugging, linting and smart autocompleting Python code with lightning fast speeds and precision.
Visual Studio Code installed with these necessary extensions.PyCharm: The Python IDE for Professional Developers.
Visual Studio Code installed with these necessary extensions.
PyCharm: The Python IDE for Professional Developers.
With that you are ready to begin your journey into machine learning and beyond.