Keras is a deep learning library which can be used on the enterprise platform, by deploying it on a container. In this article, we see how to install Keras on Docker and Google’s Cloud ML.
Installing Keras on Docker
One of the easiest ways to get started with TensorFlow and Keras is running in a Docker container. A convenient solution is to use a predefined Docker image for deep learning created by the community that contains all the popular DL frameworks (TensorFlow, Theano, Torch, Caffe, and so on). Refer to the GitHub repository at https://github.com/saiprashanths/dl-docker for the code files. Assuming that you already have Docker up and running (for more information, refer to https://www.docker.com/products/overview), installing it is pretty simple and is shown as follows:
The following screenshot, says something like, after getting the image from Git, we build the Docker image:
In this following screenshot, we see how to run it:
From within the container, it is possible to activate support for Jupyter Notebooks (for more information, refer to http://jupyter.org/):
Access it directly from the host machine on port:
It is also possible to access TensorBoard (for more information, refer to https://www.tensorflow.org/how_tos/summaries_and_tensorboard/) with the help of the command in the screenshot that follows, which is discussed in the next section:
After running the preceding command, you will be redirected to the following page:
Installing Keras on Google Cloud ML
Installing Keras on Google Cloud is very simple. First, we can install Google Cloud (for the downloadable file, refer to https://cloud.google.com/sdk/), a command-line interface for Google Cloud Platform; then we can use CloudML, a managed service that enables us to easily build machine, learning models with TensorFlow. Before using Keras, let’s use Google Cloud with TensorFlow to train an MNIST example available on GitHub. The code is local and training happens in the cloud:
In the following screenshot, you can see how to run a training session:
We can use TensorBoard to show how cross-entropy decreases across iterations:
In the next screenshot, we see the graph of cross-entropy:
Now, if we want to use Keras on the top of TensorFlow, we simply download the Keras source from PyPI (for the downloadable file, refer to https://pypi.python.org/pypi/Keras/1.2.0 or later versions) and then directly use Keras as a CloudML package solution, as in the following example:
Here, trainer.task2.py is an example script:
from keras.applications.vgg16 import VGG16 from keras.models import Model from keras.preprocessing import image from keras.applications.vgg16 import preprocess_input import numpy as np # pre-built and pre-trained deep learning VGG16 model base_model = VGG16(weights='imagenet', include_top=True) for i, layer in enumerate(base_model.layers): print (i, layer.name, layer.output_shape)
Thus we saw, how fairly easy it is to set up and run Keras on a Docker container and Cloud ML.
If this article interested you, make sure to check out our book Deep Learning with Keras, where you can learn to install Keras on other popular platforms such as Amazon Web Services and Microsoft Azure.