Easy guide to installing keras + Tensorflow
Getting ready for deep learning is not as hard as you might think. (minus the modelling and architecture process, underlying mathematics)
In this post, we will go through a simple tutorial to get started with deep learning on your pc/ laptop. Many people are freaked out at the initial set up process. It is not as complex as you think so, let us get on to it! At the end of this post, you will be able to install tensorflow with keras backend on your laptop and you will be able to start running some deep learning models like a scientist!
I will assume you have anaconda3 environment installed, because it is really the best environment when it comes to doing data science using python.
Also, make sure you have a pretty decent Nvidia graphics card if you are using a laptop. (although this pretty much applies to desktop) Personally, I use a gaming laptop for doing much of my data science work.
With that, let us begin.
Tutorial
- There will be 2 prerequisites to be able to run deep learning. We need to have CUDA Toolkit 8.0 as well as cuDNN v5.1 for CUDA 8.0. As for now, you have to exact version of the 2 programs.
we will get cuDNN v5.1 here as well as Cuda 8.0 under the archives here
- Once you have downloaded them. Install CUDA 8.0. I believe at the point where I was installing, they also required me to install Microsoft visual studios. If during installation, you were prompt, then go ahead and install MVS then return to install Cuda. (I downloaded the community version)
- Now, place your entire cuDNN file (unzipped) into your C: directory. Once that is done, you will have to add this to the environment path.
C:\cudnn-8.0-windows10-x64-v5.1\cuda\bin
If you do not understand about environmental path, what you need to do is: Right click my computer > advanced system settings > environmental variables. You will see system variables. Scroll to this PATH variable and add the above line into it.
- Create a new python environment solely for this. To do so, open anaconda prompt and type this:
conda create -n deeplearning python=3.5 numpy scipy matplotlib spyder ipython notebook
You can replace deeplearning
with any name you want to. deeplearning
is the name of the new python environment you will be creating. In this tutorial, I will be creating my environment as deeplearning
- Once done, you must activate this environment. In future, if you want to do your deep learning, you must first activate this environment before proceeding:
Then with deeplearning environment activated,
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/windows/gpu/tensorflow_gpu-1.0.1-cp35-cp35m-win_amd64.whl
Once it is done, continue to install keras:
- At this point, you are done! Download this sample py file and run it. It should take few minutes, indicating everything is done correctly.
To run the file, again, go to anaconda prompt,
activate deeplearning python mnist_mlp.py
Others
- if for some reason you are not installing correctly, you can check if tensorflow is using gpu. You should see GPU appearing.
from tensorflow.python.client import device_lib print(device_lib.list_local_devices())
Future
In future, I will go through some compiled methods to set up your own cloud instances (AWS.. etc), since most people will not have a powerful local machine to go for deep learning. Moreover, there is a chance that running keras/tensor on your machine might damage it in the long run.
Tags: deep, keras, learning, python, tensorflow
Categories: tutorial
Updated: October 27, 2017
Originally published at germayneng.github.io on October 27, 2017.