Hashwanth Gogineni's other Models Reports

Major Concepts

 

Sign-Up/Login to access Several ML Models and also Deploy & Monetize your own ML solutions for free

Models Home » Domain Usecases » Agriculture » Corn Leaf Infection Detection

Corn Leaf Infection Detection

Models Status

Model Overview

Corn Diseases:


Corn is one of India's most popular food grains, and crop loss due to diseases substantially affects the Indian economy and threatens food availability. However, recent access to smart devices can automatically diagnose corn diseases and prevent severe crop losses.




Fall Armyworm in Corn:


'Fall armyworm' can be one of the most difficult pests to control in a cornfield. Late planted cornfields and later maturing hybrids are more likely to get infected. Fall armyworm causes leaf feeding damage as well as direct injury to the ear part. While fall armyworms can damage corn leaves in nearly all stages of development, they will concentrate on later plantings that have not silked yet. Like European corn borers, fall armyworms can only be effectively controlled while the larvae are small. Therefore, early detection and proper timing of an insecticide application are a must.  


Each summer, 'adult moths' move northward in progressive stages from overwintering sites along the Gulf Coast and begin appearing in 'Kentucky' in late June or early July of the year. The spherical 'grey eggs' are laid in clusters of 50 to 150. Egg masses are covered with a coating of 'moth scales.' 'Larvae' hatch in 3 to 5 days and move to the whorl.




Why Corn Leaf Infection Detection?

Corn Infection is a huge problem for farmers, leading to loss of production or financial distress. The project will help Agriculture sectors for making systems that can help solve farmers' problems using Artificial Intelligence.


 Dataset:


The dataset includes '4,226' images belonging to 2 classes, i.e., 'Healthy corn' and 'Infected' accordingly. 




Convolutional Neural Network (CNN): 


'CNN' was first developed and used around the 1980s. The most that a CNN could do was recognize handwritten digits. It was mostly used in the postal sectors to read zip codes, pin codes, etc. The important thing to remember about any deep learning model is that it requires a large amount of data to train and requires a lot of computing resources. This was a major drawback for CNNs at that period, and hence CNNs were only limited to the postal sectors and failed to enter the world of machine learning.


In 2012 Alex Krizhevsky realized that it was time to bring back the branch of deep learning that uses multi-layered neural networks. The availability of large sets of data, more specific ImageNet datasets with millions of labelled images, and an abundance of computing resources enabled researchers to revive CNNs.




In deep learning, a convolutional neural network (CNN/ConvNet) is a class of deep neural networks most commonly applied to analyze visual imagery. When we think of a neural network, we think about matrix multiplications, but that is not the case with ConvNet. Instead, it uses a special technique called Convolution. Convolution is a mathematical operation on two functions that produces a third function that expresses how the shape is modified by the other.


Understanding Code:


Classifying plant species or diseases in plants can sometimes be challenging for the human eye, especially for people with limited experience in the field. Thus, we use a deep learning approach to try and minimize this error.


First, let us import the required libraries for our project.


import os
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Conv2D, Dropout, Flatten, MaxPool2D
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.preprocessing.image import load_img
from tensorflow.keras.preprocessing.image import array_to_img, img_to_array
from tensorflow.keras.models import load_model

 


Now, let us load the data into the system and perform some data augmentation techniques like 'shear_range', 'zoom_range', 'horizontal_flip'.


batch_size = 32
img_height, img_width=256,256
train_datagen = ImageDataGenerator(rescale=1./255,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
validation_split=0.2)

train_generator = train_datagen.flow_from_directory(
root_dir,
target_size=(img_height, img_width),
batch_size=batch_size,
class_mode='categorical',
subset='training')

validation_generator = train_datagen.flow_from_directory(
root_dir,
target_size=(img_height, img_width),
batch_size=batch_size,
class_mode='categorical',
subset='validation')

 


Finally, let us apply the best model that can fit our data.
Here I used 6 'Conv2D' layers, 3 'MaxPool2D' layers and 1 'flatten' layer, 1 'Dropout' layer, 2 'Dense' layers to get the best out of our data.


model = Sequential()

model.add(Conv2D(32, (3, 3), input_shape = (img_height, img_width, 3), padding="same", activation = 'relu', data_format = 'channels_last'))
model.add(Conv2D(32, (3, 3), activation='relu', padding="same"))
model.add(MaxPool2D(pool_size=(3, 3)))

model.add(Conv2D(64, (3, 3), activation='relu', padding="same"))
model.add(Conv2D(64, (3, 3), activation='relu', padding="same"))
model.add(MaxPool2D(pool_size=(3, 3)))

model.add(Conv2D(128, (3, 3), activation='relu', padding="same"))
model.add(Conv2D(128, (3, 3), activation='relu', padding="same"))
model.add(MaxPool2D(pool_size=(3, 3)))

model.add(Flatten())
model.add(Dropout(0.25))
model.add(Dense(256, activation='relu'))
model.add(Dense(2, activation='softmax'))

model.summary()


As you can see I used 'binary_crossentropy' and 'accuracy' as accuracy metrics.


lr=1e-03
epochs=15

opt = Adam(lr=lr, decay=lr / epochs)

model.compile(loss="binary_crossentropy", optimizer=opt,metrics=["accuracy"])

history=model.fit_generator(
train_generator,
steps_per_epoch=len(train_generator),
validation_data=validation_generator,
validation_steps=len(validation_generator),
epochs=epochs,
verbose=1,
workers=32)


Finally, I used 'matplotlib.pyplot' to generate our model's performance's graph.


acc = history.history['accuracy']
val_acc = history.history['val_accuracy']

loss = history.history['loss']
val_loss = history.history['val_loss']

epochs = 15

epochs_range = range(epochs)

plt.figure(figsize=(8,8))
plt.subplot(1,2,1)
plt.plot(epochs_range, acc, label="Training Accuracy")
plt.plot(epochs_range, val_acc, label="Validation Accuracy")
plt.legend(loc = "lower right")
plt.title("Training and Validation Accuracy")

plt.subplot(1,2,2)
plt.plot(epochs_range, acc, label = "Training Loss")
plt.plot(epochs_range, val_loss, label = "Validation Loss")
plt.legend(loc = "upper right")
plt.title("Training and Validation Loss")
plt.show()

print(acc)



Also, let us have a look at our model's classification report.


# Classification Report

from sklearn.metrics import classification_report

test_labels=test_generator.classes
predictions=model.predict_generator(test_generator, verbose=1)
y_pred = np.argmax(predictions, axis=-1)
print(classification_report(test_labels, y_pred))



As you can see the model performed well and is now production-ready.


Thank you for your time.
 


0 comments