Creating Keras Model for IBM Watson Machine Learning

In this blog, we will learn how to create and deploy our own deep learning models on IBM Watson platform. The aim of this blog is not to teach about creating a deep learning model in Keras. It is merely to emphasize the workflow of IBM Watson Machine Learning service. The blog aims to teach about creation of a compatible model that can easily be deployed on IBM Cloud.
There are multiple ways to create, train and deploy a deep learning model on IBM Watson Machine Learning.
- Create and train the model online
- Create the model offline and train online
- Create and train the model offline
We will be pursuing the third option in this blog then head on to deploying it online.
Prerequisites:
- IBM Cloud Account
- Keras (2.2.4)
- Tensorflow (1.14)
To know about the supported frameworks you may check here : Supported frameworks
Since we have the requirements down, let’s begin.
The Project
We have created a model to recognise mobile phone in an image. This is to thwart mobile phone face spoofing. This project is being performed in a controlled environment where other kind of spoofing devices will not be allowed. Even a picture of a person’s face won’t be allowed.
The project is present on GitHub at this link.
Gathering the data
We used Faces in the Wild data set for faces. The faces were put in a several mobile phones and pictures were taken. To increase the quality of the data set, we performed data augmentation. The data is separated into two folders namely — Face Images and Mobile Images.
The model
To create the model we approached transfer learning. We tested several models like ResNet50, NasNet and VGG16. VGG16 turned out to provide to be the best in our scenario.
Following steps are required to create a model that is compatible with IBM Machine Learning Service:
- Create the model in a supported framework as provided in the link above.
- After the model is created, it should be saved in correct format. It can be saved with (in case of offline training, our scenario) or without weights.
- Store the model on IBM Watson Machine Learning. (we will see this in the next blog).
- Deploy the model
- Use the Keras model.save() API to save the model in HDF5 file format.
- File name of the saved model file specified in
.save()must have extension as .h5 or .hdf5 - The serialized model must be compressed in <model>.tar.gz format. IBM Watson Machine Learning can only store the model in this format if deployed manually.
To know about supported model formats for importing visit here.