Convolutional Neural Network on Nigerian Foods

Richard Ogunyale
4 min readApr 6, 2019

Most data set used in machine learning and deep learning are datasets that are foreign with the Nigerian System. Hence, it delights me to get a data set familiar with Nigeria to train a convolutional neural network on. Due to insufficiency of dataset, I limited the scope of this model to train on Yoruba foods.

An Image from the dataset

First, what are convolutional neural networks? A Convolutional neural network is a Deep Learning algorithm which can take in an input image, assign importance (learnable weights and biases) to various aspects objects in the image and be able to differentiate one from the other. I will just be taking you briefly on the way I built a convolutional neural network on some Yoruba Foods.

Source: Google

I would be running you briefly on how I train the images of some yoruba foods using convolutional neural network. There are about 338 images of yoruba foods which are distributed as seen in the image below.

Distribution of Image data

The deep learning framework used for training of this model is Keras with tensorflow backend. Firstly, the csv file which contains the label and file name of the image is imported using pandas. Then, the train image is imported using the code below.

As part of preprocessing the data, the labels are hard encoded so as to enable it to be passed into the convolutional neural network. The size of the image are 170 x 140. The input shape of the image is now (170 x 140 x 3) since it is an RGB image.

In building the architecture of the Neural Network model,we call the sequential model in keras framework. The Convolutional 2D of size 32 and kernel size is (3,3) which is then passed into the Rectified linear unit (relu) activation function. MaxPooling is then performed on the image with a pool size of 2 x 2. It is noticed that during the MaxPooling operation, the image sizes are halved. It is advisable to read more on the convolution and Maxpooling operation to get a full hang of the convolutional neural network. Seen below is the code used to build the convolutional network.

The model summary for the convolutional neural network can be seen below

Model Summary

A total of 270 images was used to train the model and a total of 68 images was used to validate the model. The model was trained on epochs. The plot of accuracy against the epochs can be seen in the graph below:

The model generated an accuracy of 85.294% which is quite acceptable. The Classification report generated using the scikit learn library can be seen below:

Classification Report

The confusion matrix generated by the model on the validation set is seen below:

This convolutional Neural Network model can be applied to locally collected data, and hence can be used to predict the classes of some foods accurately since it has an accuracy of over 80% on the validation set.

Finally, I would advise that for more learning, I would recommend Deep Learning with Python by Francois Chollet , the brains behind keras. You can find the link to the full code and data set here.

📝 Read this story later in Journal.

🗞 Wake up every Sunday morning to the week’s most noteworthy Tech stories, opinions, and news waiting in your inbox: Get the noteworthy newsletter >

--

--