Image Classification Using Keras

I wrote an article titled “Image Classification Using Keras” in the December 2018 issue of Visual Studio Magazine. See https://visualstudiomagazine.com/articles/2018/12/01/image-classification-keras.aspx.

Keras is a neural network library. Keras actually is a layer of abstraction on top of the TensorFlow library. The idea is that TensorFlow operates at a low level and is very difficult to use. Keras gives developers a much easier-to-use interface for creating deep neural networks.

In my mind, there are five basic types of problems that are well-suited for neural networks: multiclass classification, binary classification, regression, CNN image classification, and LSTM sentiment analysis.

In my article, I show how to use Keras to create a prediction model for the well-known MNIST image data set. Each image has size 28 pixels by 28 pixels. Each pixel is a grayscale value between 0 and 255. Each image is a hand-drawn digit, ‘0’ through ‘9’. The goal is to read in a set of 28×28 = 784 pixels and predict the digit that’s represented.

My demo program uses a convolutional neural network (CNN) which is a clever architecture that looks at small areas of an image, rather than at the entire image as a whole. This gives a better prediction model, scales well to larger images with possibly millions of pixels, and is resistant to small changes in the positioning of the image (“shift invariance”).

The MNIST dataset has a total of 70,000 images and is divided into a training set (60,000 images, 6,000 of each digit), and a test set (10,000 images).

An interesting aspect of image classification that I didn’t have time to discuss in my article is that even though CNN networks were designed specifically for image classification, CNNs are being used with great success is other problem scenarios.



Keras means horn in Greek. Left: I love the Horatio Hornblower historical fiction novels by C.S. Forester. Left Center: The 1951 movie “Horatio Hornblower” starring Gregory Peck is very good. Right Center: The British series of TV movies from 1998 to 2003, starring Ioan Gruffudd, are also excellent. Right: Author Alexander Kent wrote a similar series of excellent novels in the 1970s. The themes of courage in the face of adversity, loyalty and friendship, patriotism, and resilience are not corny in my mind – they’re important principles to try and honor (as best as possible).

This entry was posted in Keras. Bookmark the permalink.