SETTING UP AND USING ANACONDA WITH KERAS AND TENSORFLOW

//SETTING UP AND USING ANACONDA WITH KERAS AND TENSORFLOW

SETTING UP AND USING ANACONDA WITH KERAS AND TENSORFLOW

SETTING UP AND USING ANACONDA WITH KERAS AND TENSORFLOW

Hi fellow geeks, in this blog I’ll be setting up Anaconda with eras and ensorflow both in windows and on Ubuntu Linux. But before we get into the implementation process let’s look at what each of these terms mean.

Anaconda is open source software bundle consisting of package management tools, environment management tools, pip and related python libraries. It also includes Python and R languages by default as well as Spyder IDE and Jupyter Notebook along with a bunch of data science related tools.

According to jupyter.org:

The Jupyter Notebook is an open-source web application that allows you to create and share documents that contain live code, equations, visualizations and explanatory text. Uses include: data cleaning and transformation, numerical simulation, statistical modeling, machine learning and much more.

Anaconda by default includes its own package manager which can be used to install dependencies for a project. It’s more like pip (python package manager), npm (node package manager) or nuget package manager on .net. Users can use conda as the installation command whilst using Anaconda. Anaconda can be downloaded from Continuum website (the link is provided in references section).

Keras is a deep learning library written in python. It is basically a high level neural network capable of running on top of either Tensorflow (Google)Theano or CNTK (Microsoft Cognitive Toolkit).

Tensorflow is an open source machine learning library from Google.

According to TensorFlow:

TensorFlow is Google Brain‘s second generation machine learning system, released as open source software on November 9, 2015. While the reference implementation runs on single devices, TensorFlow can run on multiple CPUs and GPUs (with optional CUDA extensions for general-purpose computing on graphics processing units). TensorFlow is available on 64-bit LinuxmacOSWindows, and mobile computing platforms including Android and iOS.”

So now we know what each of these terms mean, let’s get started with installation and configuration setup. On a Windows 10 machine we just need to install Anaconda and then install Keras with Tensorflow afterwards by using conda. This is necessary because as of now there is an issue with installing Keras directly on windows, although we can just use pip to install all dependencies while in Linux systems. Pip install does not work well on windows for scipy and numpy the libraries on which Keras depends. It is for exactly this reason we’ll be using Anaconda to install all necessary stuff.

First, we’ll download and install Anaconda from their website (link provided in references), then we’ll run each of following commands to setup a virtual environment from conda, have it activated and then install Keras, Theanoand Tensorflow.

C:\conda create --name neuralnets python=3.5
C:\activate neuralnets
(neuralnets) C:\ conda update conda
(neuralnets) C:\ conda update –all
(neuralnets) C:\ conda install theano
(neuralnets) C:\ conda install mingw libpython
(neuralnets) C:\pip install tensorflow
(neuralnets) C:\pip install keras

Alternatively install directly from git repositories for Theano and Keras

pip install git+git://github.com/Theano/Theano.git
pip install git+git://github.com/fchollet/keras.git

If you’ve performed each of above commands sequentially you should have a functional setup for the mentioned libraries. Please note to use Theano we could need to setup a CUDA installation. Installing CUDA can make use of NVidia graphic GPU’s for improved Theano prediction performance.

According to Wikipedia:

 “CUDA is a parallel computing platform and application programming interface (API) model created by Nvidia.

Although we can use CUDA for an improved performance while running Theano but it is not a must to have it installed we can use the CPU based version just update the,“.theanorc”  file and set “device = cpu. You could open find this file after typing “%USERPROFILE%” from run command

To modify the setting for Keras and configure it to use a machine learning engine like Theano (By default Kerasuses Tensorflow as default) we can create a new folder (named as “.keras”) and a file (named as keras.json)   under the %USERPROFILE%

We’ll add below code in keras json file:

{
     "floatx": "float32",
     "epsilon": 1e-07,
     "image_dim_ordering": "th",
     "backend": "theano"
 }

Next to install and use Keras on Ubuntu we’ll just need to run following commands as sudo using a terminal:

pip install keras theano tensorflow mingw libpython

That’s it for now folks! I’ll be covering up more interesting topics in my upcoming blogs. So please feel free to share your critiques and suggestions.

Related Links as reference:

https://en.wikipedia.org/wiki/Anaconda_(Python_distribution)
https://stackoverflow.com/questions/42096280/how-is-anaconda-related-to-python
https://www.continuum.io/anaconda-overview
https://unidata.github.io/online-python-training/introduction.html
https://www.tensorflow.org/install/
https://keras.io/getting-started/
https://en.wikipedia.org/wiki/TensorFlow
http://ankivil.com/installing-keras-theano-and-dependencies-on-windows-10/
https://stackoverflow.com/questions/34097988/how-do-i-install-keras-and-theano-in-anaconda-python-on-windows
http://timmyreilly.azurewebsites.net/python-pip-virtualenv-installation-on-windows/
https://stackoverflow.com/questions/29863720/conda-virtual-envinment-not-changing-under-windows

By |2018-10-25T08:01:47+00:00September 4th, 2018|Technology|0 Comments

About the Author:

Leave A Comment