Classifying Soy Plagues using Convolutional Neural Networks
By: Lucas Solano
Tags: Artificial Intelligence, Convolutional Network, Image Processing, Classification Algorithms, Deep Learning

To improve our model, we also include in our dataset some negative images. That is, some images that are not part of the labeled classes. These pictures were mainly of other insect species that could have been easily mistaken as the ones in our class labels. Our dataset was not that large, but we made sure to choose high-quality images.

For the Southern Green Stink Bug, 36 images were selected.

Neotropical Brown Stink Bug, 56 images.

29 images were selected for the Velvetbean Caterpillar.

Red-banded Stink Bug had 24 images.

There were 125 negative images.

Pre-processing

Firstly, all images were resized using Imutils’ resize function. The bigger dimension on width or height was chosen and resized to the size of the smaller dimension of the two. For example, if the width is smaller than the height, then the height would be resized to the size of the width.

Secondly, a data normalization technique was applied, a mean pre-processor. In this stage, we computed the average Red, Green, and Blue pixel intensities between all images in the training dataset. with these averages, we performed a pixel-wise subtraction of these values from our input images.

The next step was, in order to reduce overfitting, we had to regularize the data. For that matter, we randomly sampled regions of some images during the training process. This strategy was only applied when the spatial dimensions of the input images were larger than what the CNN expected.

After that, we applied an oversampling method, on which we cropped the corners of the input image plus the center region, and then we flipped it horizontally, for a total of ten samples per input image. This method usually increases classification accuracy.

CNN Model

Convolutional Neural Networks, or CNNs, are a class of deep neural networks used most commonly in image processing. It takes some aspects of the image and differentiates them from one another. If you want to take a closer look at CNNs, there is a simple guide on the following website:

In our problem, we choose to implement an architecture based on AlexNet architecture. AlexNet is a leading architecture for any object-detection task and may have huge applications in the computer vision sector of artificial intelligence problems.

Our architecture can be separated into five blocks. Three of them with convolutional layers combined with linear rectifier activation functions, batch normalizations, overlapping poolings, and dropouts. And the latter two with fully connected layers.

For the implementation, we used an API called Keras that is a high-level API of TensorFlow for creating and training deep learning models more easily.

The neural network ran through a hundred epochs, and we had the following results:

Loss/Accuracy for each epoch for both the training and validation sets

Metrics for the classification of each class label

As we can see, for all classes we had a pretty good performance overall in the classification problem. For some classes, the algorithm could predict almost all of the test samples correctly. The final accuracy on the test set was 68.57%.

It is valid to point that most of the insects treated in this classification problem are considerably similar. Three of them are of the same family of insects, which could make the classification problem considerably harder. Another point to consider is that if the dataset was bigger, probably we could have higher final accuracy.

Conclusion and some remarks

With this deep learning application, we could practice the pipeline for an image classification problem and also solve a real-world problem that could be implemented for the sponsor company in order to assist in plague control for soy plantations.

The algorithm could classify with good performance between the labeled classes, which could help greatly in the choice of the method of plague control that can be used in a soy plantation based on the specimen of insect found there.

The code exemplified in this article is available at:

https://github.com/camilabga/cocamar-bugs