Installing Keras for deep learning

Installing Keras for deep learning



The purpose of this blog post is to demonstrate how to install the Keras library for deep learning. The installation procedure will show how to install Keras:
  • With GPU support, so you can leverage your GPU, CUDA Toolkit, cuDNN, etc., for faster network training.
  • Without GPU support, so even if you do not have a GPU for training neural networks, you’ll still be able to follow along.
Let me start by saying that Keras is my favorite deep learning Python library. It’s a minimalist, modular neural network library that can use either Theano or TensorFlow as a backend.
Furthermore, the primary motivation behind Keras really resonates with me: you should be able to experiment super quickly — going from idea to result, as fast as possible.
Coming from a world that mixes both academia and entrepreneurship, the ability to iterate quickly is extremely valuable, especially in the deep learning world where it can take days to weeks to train just a single model.
I’ll be using Keras extensively in the coming PyImageSearch blog posts, so make sure you follow this tutorial to get Keras installed on your machine!

Installing Keras for deep learning

I’ll be making the assumption that you’ve been following along in this series of blog posts on setting up your deep learning development environment:
I’ll be using my same Amazon EC2 g2.2xlarge instance running Ubuntu 14.04 as I have in previous tutorials — feel free to use the same machine you’ve been using to follow along as well.
Overall, installing Keras is a 5-step procedure, with three of these steps being optional.
The first optional step is whether or not you would like to use Python virtual environments — I suggest that you do, but that decision is entirely up to you.
The second optional step is whether or not you want to use the GPU to speedup training your neural networks — this is obviously dependent on whether you own a CUDA-compatible GPU. The Keras library can run on the CPU just fine, but if you really want to train deep neural networks, you’ll want to get a GPU installation setup.
The final optional step is whether or not you would like to have OpenCV bindings in your Python virtual environment along with your Keras installation. If you do, you’ll want to pay attention to Step #4.
With all that said, let’s get started!

Step #1: Create a separate Python virtual environment (optional)

If you’ve been following along in this series of posts, then you already know that I like using Python virtual environments. Utilizing virtual environments is especially important when we start working with various deep learning libraries (Keras, Theano, mxnet, TensorFlow, etc.) and versioning issues can easily occur (especially surrounding which version of Theano is used).
Because of the problems related to conflicting library versions, I suggest creating a virtual environment exclusively for Keras-based projects:
This will create a Python virtual environment named keras . Anytime you would like to access this virtual environment, just use the workon  command followed by the name of the virtual environment:
In this case, we can access the keras  virtual environment by executing the following command:

Step #2: Install Keras

Installing Keras is a breeze — pip  can do all the hard work for us. First, we need to install a few dependencies:
We also need to install Theano. You can certainly use pip  to install Theano; however, it’s important to note that Keras always uses the latest version of Theano, which is not always the version that is on PyPI. Thus, we should instead install Theano using the following command:
An alternative method to install Theano is to clone the repository from GitHub and use thesetup.py  script:
From there, we can use pip  to install Keras as well:
After Keras has finished installing, you can verify the install by opening up a terminal, accessing the keras  virtual environment, and then importing the library (see Step #5 for an example on how to do this).
However, if you want to optimize Keras so that it uses your GPU, CUDA Toolkit, and cuDNN, you’ll want to proceed to Step #3.

Comentarios

Entradas populares de este blog

remote tim ferris