How to Install Keras for Anaconda in Linux
I've been using Anaconda Python for most of my Machine Learning experiments, mainly because of the flexibility it gives with the isolated Python environments. I recently did a post on how to install Keras on Anaconda on Windows.
I'm planning to switch to Linux for few of my experiments, so I decided to try out setting up Anaconda Python and Keras from scratch on Ubuntu. I'll be using the latest Ubuntu 16.10 (Yakkety Yak) 64-Bit for this.
Note: The screenshots I captured are from a virtual machine with Lubuntu 16.10 (the LXDE flavor of Ubuntu). But the steps and commands are exactly the same for the standard Ubuntu desktop as well.
First and foremost, get and install the latest updates in Ubuntu, (Reboot the machine if necessary after updating.)
sudo apt-get update sudo apt-get upgrade
Then, we'll install the following necessary packages,
sudo apt-get install build-essential cmake git unzip pkg-config sudo apt-get install libopenblas-dev liblapack-dev
Now, on to installing Anaconda. Head over to the Anaconda Python Downloads page, and get the Linux installer for Anaconda. We'll be getting the Python 3.5 64-Bit package.
Download the Anaconda Python 3.5 64-Bit package for Linux |
This will download a file named Anaconda3-4.2.0-Linux-x86_64.sh (the version numbers might be different based on the latest version available at the time of the download).
Open a terminal, and navigate to the location of the downloaded file, and run the following command to start the installation,
bash Anaconda3-4.2.0-Linux-x86_64.sh
You need to include the 'bash' command even if you're not using the bash shell.
Start the Anaconda Installation |
Note: When installing Anaconda on the default location, you don't need root access, so there's no need to 'sudo'.
Accept the defaults…
Accept the defaults of the Installation |
… and let it install,
Installation ongoing |
At the end of the installation, it will ask whether to add the Anaconda install location to your PATH. Say 'yes' to that,
Select the option to add Anaconda to the PATH |
After the installation completed, close the terminal, and open a new one.
Now, we are ready to create an Anaconda environment and install Keras in it.
Create a new environment (I'll name it 'keras-test') with the following packages.
conda create --name keras-test numpy scipy scikit-learn pillow h5py
Having these commonly used packages installed will make your life easier later on.
Creating the Anaconda environment and installing the packages |
Once the environment is created, and the package installations are finished, activate the environment,
source activate keras-test
I'll be initially using Keras with the Theano backend, so I'll install Theano first.
pip install --upgrade --no-deps git+git://github.com/Theano/Theano.git
(I'll be doing a separate guide for installing TensorFlow on Ubuntu)
Finally, install Keras from pip,
pip install keras
Installing Keras on Anaconda |
Keas will by default try to use the TensorFlow backend. So, when using Theano, remember to switch the backend in Keras Config. See my post Switching between TensorFlow and Theano on Keras on how to switch backends.
Finally, let's test the Keras installation by invoking the Python interpreter in our Anaconda environment and running the following command,
python >>> import keras Using Theano backend.
Keras on Anaconda on Linux, ready for action |
If you don't get any errors, then we are ready to start developing Machine Learning models on Keras on Linux.
Related posts:
Getting Keras working with Anaconda Python
Switching between TensorFlow and Theano on Keras
Build Deeper: Deep Learning Beginners' Guide is the ultimate guide for anyone taking their first step into Deep Learning.
Get your copy now!
How to Install Keras for Anaconda in Linux
Source: https://www.codesofinterest.com/2016/11/setting-up-keras-anaconda-ubuntu.html
0 Response to "How to Install Keras for Anaconda in Linux"
Post a Comment