Image classification with Keras - salekd/santa GitHub Wiki

This section describes how to build a simple image classifier in Keras to detect Santa (and not-Santa).


Prepare a dataset

The first step is to get a dataset for training. I used directly the dataset provided by Adrian Rosebrock from his tutorial here: https://www.pyimagesearch.com/2017/12/18/keras-deep-learning-raspberry-pi/

He also provides instructions on how to acquire such dataset here: https://www.pyimagesearch.com/2017/12/04/how-to-create-a-deep-learning-dataset-using-google-images/

Reading the Keras documentation the related code referenced below, I decided to use ImageDataGenerator. ImageDataGenerator is able to infinitely read data in batches from a directory. The classes of the images are inferred from the directory structure. Further manipulations, such as rotation, can be applied to the images which comes handy when training on a limited dataset.


Build a model

Following the Keras documentation, I decided to use the model from there, a simple stack of 3 convolution layers with a ReLU activation and followed by max-pooling layers. This is very similar to the architectures that Yann LeCun advocated in the 1990s for image classification.

Train a model:

python train_santa_model.py

Test detecting Santa and not-Santa:

python detect_santa.py data/examples/santa_01.png
python detect_santa.py data/examples/manhattan.png

I recommend reading the documentation further where transfer learning based on a pre-trained VGG16 model is described. Such examples also take place in this repository, see https://github.com/salekd/santa/blob/master/train_santa_model_vgg_bottleneck.py and https://github.com/salekd/santa/blob/master/train_santa_model_vgg.py