Tarun Reddy'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 » Cotton Disease Prediction using Deep learning

Cotton Disease Prediction using Deep learning

Models Status

Model Overview

                                                                                          

It is very important to get an accurate diagnosis of plant diseases for global health and well-being. In this ever-changing environment, identifying the disease including early prevention is important to avoid problems that we might face otherwise. Some of these problems could have devastating impacts on humanity including a global shortage of food. It is crucial to prevent unnecessary waste of financial resources achieving a healthier lifestyle, by addressing climate change from an ecological perspective. It is difficult for the naked eye of a human being to catch all sorts of problems with plant diseases. Also doing this time and time again is also laborious and unproductive work. In order to achieve accurate plant disease detection, a plant pathologist should possess good observation skills so that one can identify characteristic symptoms. An automated system designed to help identify plant diseases by the plant’s appearance and visual symptoms could be of great help. This can be deployed in agricultural fields so that the whole pipeline can be automated. This would not only lead to better efficiency as machines could perform better than humans in these redundant tasks but also improve the productivity of the farm. Our work solves the above-mentioned problem of automating plant disease classification using deep learning and computer vision techniques.

Disease detection in plants plays an important role in agriculture as farmers have often to decide whether the crop they are harvesting is good enough. It is of utmost importance to take these seriously as they can lead to serious problems in plants due to which respective product quality, quantity, or productivity is affected. Plant diseases cause a periodic outbreak of diseases leading to large-scale death which severely affects the economy. These problems need to be solved at the initial stage, to save the lives and money of people. Automatic classification of plant diseases is an important research topic as it is important in monitoring large fields of crops and at a very early stage, if we can detect the symptoms of diseases when they appear on plant leaves. This enables computer vision algorithms to provide an image-based automatic inspection. Comparatively, manual identification is labor-intensive, less accurate, and can be done only in small areas at a time. By this method, the plant diseases can be identified at the initial stage itself and the pest and infection control tools can be used to solve pest problems while minimizing risks to people and the environment.

Farming is one wide area and that plays a vital part for our country. While monitoring infections in plants with the assistance of experts can be a costly process, there is a requirement for a framework that can identify the infections as it can acquire upheaval observing enormous fields of yield and afterward plant leaves can be cured as quickly as time after identification of disease. There are countless infections that influence cotton and a lot more other plants.

ACCURACY : 
Accuracy: 92%
Val Accuracy: 86%

Let us import the required libraries

import tensorflow as tf
from tensorflow.keras.layers import Flatten, Dense
from tensorflow.keras.applications import VGG19
from tensorflow.keras.preprocessing.image import ImageDataGenerator

now let's create a variable named vgg and use VGG19

vgg= VGG19(include_top= False, weights= "imagenet", input_shape= (224, 224, 3))

for layer in vgg.layers:
layer.trainable = False

x= Flatten()(vgg.output)

pred= Dense(4, activation= "softmax")(x)

In the next step let us build the model using keras

model= tf.keras.Model(vgg.inputs, pred)

Now let us compile the model

model.compile(loss= "categorical_crossentropy", optimizer= "adam", metrics= ["accuracy"])

By using imagedatagenerator let us create a variable named train_generator


train_generator= ImageDataGenerator(rescale=1./255,  shear_range=0.2, zoom_range=0.2, horizontal_flip=True)

now repeat the above step and create a variable test_generator

test_generator= ImageDataGenerator(rescale=1./255,  shear_range=0.2, zoom_range=0.2, horizontal_flip=True)

lets now assign the training images into train_data and testing images into test_data


train_data = train_generator.flow_from_directory( 'E:\\CottonDisease\\train', target_size=(224, 224),
batch_size=32,class_mode = 'categorical')


test_data = test_generator.flow_from_directory( 'E:\\CottonDisease\\test', target_size=(224, 224),
batch_size=32,class_mode = 'categorical')


now check the model summary

model.summary()



h= model.fit_generator(train_data, steps_per_epoch= len(train_data), epochs=10, validation_data= test_data, validation_steps= len(test_data))


now let us plot a graph for accuracy and losses

import matplotlib.pyplot as plt

plt.plot(h.history['accuracy'])
plt.plot(h.history['val_accuracy'])
plt.plot(h.history['loss'])
plt.plot(h.history['val_loss'])
plt.title("Model Accuracy")
plt.ylabel("Accuracy")
plt.xlabel("Epoch")
plt.legend(["Accuracy","Validation Accuracy","loss","Validation Loss"])
plt.show()


Now in the next step let us check whether the model is predicting the images correctly or not. For this let us take an image of a fresh cotton leaf and pass it to the model.

import numpy as np
from tensorflow.keras.preprocessing import image

test_image = image.load_img('E:\\CottonDisease\\train\\fresh cotton leaf\\d.jpg', target_size = (224, 224))
imgplot = plt.imshow(test_image)
test_image = image.img_to_array(test_image)
test_image=test_image/255
test_image = np.expand_dims(test_image, axis = 0)
preds = model.predict(test_image)

preds
preds = np.argmax(preds, axis=1)

if preds==0:
print("The leaf is diseased cotton leaf")
elif preds==1:
print("The leaf is diseased cotton plant")
elif preds==2:
print("The leaf is fresh cotton leaf")
else:
print("The leaf is fresh cotton plant")



Now lets us pass another image of a diseased cotton leaf.

test_image = image.load_img('E:\\CottonDisease\\train\\diseased cotton leaf\\dis_leaf (3)_iaip.jpg', target_size = (224, 224))
imgplot = plt.imshow(test_image)
test_image = image.img_to_array(test_image)
test_image=test_image/255
test_image = np.expand_dims(test_image, axis = 0)
preds = model.predict(test_image)
preds = np.argmax(preds, axis=1)

if preds==0:
print("The leaf is diseased cotton leaf")
elif preds==1:
print("The leaf is diseased cotton plant")
elif preds==2:
print("The leaf is fresh cotton leaf")
else:
print("The leaf is fresh cotton plant")



let us pass a diseased cotton plant image and check it.

test_image = image.load_img('E:\\CottonDisease\\train\\diseased cotton plant\\dd (1)_iaip.jpg', target_size = (224, 224))
imgplot = plt.imshow(test_image)
test_image = image.img_to_array(test_image)
test_image=test_image/255
test_image = np.expand_dims(test_image, axis = 0)
preds = model.predict(test_image)
preds = np.argmax(preds, axis=1)

if preds==0:
print("The leaf is diseased cotton leaf")
elif preds==1:
print("The leaf is diseased cotton plant")
elif preds==2:
print("The leaf is fresh cotton leaf")
else:
print("The leaf is fresh cotton plant")




#Save the model as h5 file
from tensorflow.keras.models import load_model
model.save('model_inception.h5')








0 comments