FIFA-2022 Career Guide Free Tutorials Go to Your University Placement Preparation 
0 like 0 dislike
1.6k views
in AI-ML-Data Science Projects by (444 points)
edited by

DESCRIPTION:

Agriculture is the backbone of our country. Farming is the major occupation and for farming the First and the foremost important thing is the plant prevention. Damage of plant is an important issue in agriculture. There are lots of factors involving weather, fungi, artificial drying, and mechanical damage during harvest and storage which can cause damage. For which it is necessary to find that there is any disease related to plant. Early detection of disease can prevent complete damage to plants.

                            Scientists have found that on a global scale that plant disease are reducing crop yields for crops by 10 percent to 40 percent, according to a report by a UC Agriculture and Natural Resources scientist.

1 Answer

0 like 0 dislike
by (444 points)
selected by
 
Best answer

                      PLANT DISEASE DETECTION

PROBLEM:

 In Agriculture field all farmers facing the problem of plant disease.in olden days their are various way to destroy these disease but in technological time through detection we can easily detect which type of disease are available in particular plant.  

Basically we will first train our CNN models with a lot of  images of potato,pepper and tomato.

Why CNN:  As we have seen in CNN Tutorial,CNN reads a very large image in a simple manner. CNN most commonly used to analyze visual imagery and are frequently working behind the scenes in image classification.

DATASET:

Various datasets are available on internet to detect your plant disease and train your model with these datasets. We can also create our own data set and train our model. we can download data set from kaggle.To download data set GET HERE

IMPLEMENTATION:

IMPORTING LIBRARIES
# Intialization of Program. by Importing various LIbraries
import numpy as np
import matplotlib.pyplot as plt
# here we are working on Tensorflow version 2.1.0 so we need to write tensorflow.keras.
#keras is in built function in Tensorflow .
import os
import tensorflow as tf
from tensorflow.keras.preprocessing.image import ImageDataGenerator
from tensorflow.keras.layers import Dense, Input, Dropout,Flatten, Conv2D
from tensorflow.keras.layers import BatchNormalization, Activation, MaxPooling2D
from tensorflow.keras.models import Model, Sequential
from tensorflow.keras.optimizers import Adam
from tensorflow.keras.callbacks import ModelCheckpoint, ReduceLROnPlateau
from tensorflow.keras.utils import plot_model
from IPython.display import SVG, Image

NOTE:

Here we import various libraries like numpy, matplotlib, os, tensorflow etc. we use here  tensorflow version 2.1.0 and keras is also available inside this tensorflow version. we use various layers and model,optimizer for train our model. 

SPECIAL POINT
# For checking out that how many images are available in the train set we can use import OS
for types in os.listdir(
"D:\pant\drive\My Drive/train_set/"):
    print(str(len(os.listdir(
"D:\pant\drive\My Drive/train_set/"+ types)))+" "+ types+' images')
we use os.listdir for fatching list of all the images in the folder.inside this we give the path ("highlight")where images are store.here we take only train dataset images from our plant disease dataset.  

OUTPUT:

image

IMAGE LOADING :

# Complete Dataset images can be loaded using ImageDataGenerator function
img_size=48
batch_size=64
datagen_train=ImageDataGenerator(horizontal_flip=True)
train_generator=datagen_train.flow_from_directory(
"D:\pant\drive\My Drive/train_set",
target_size=(img_size,img_size),
batch_size=batch_size,
class_mode='categorical',
shuffle=True)

datagen_test=ImageDataGenerator(horizontal_flip=True)
validation_generator=datagen_test.flow_from_directory(
"D:\pant\drive\My Drive/test_data",
target_size=(img_size,img_size),
batch_size=batch_size,
class_mode='categorical',
shuffle=True)

OUTPUT:

total no. of images belonging 15 class 

DESCRIPTION:
This part of code is used to define train and test data into the model. The train dataset has 16222 images belonging to 15 classes and the test dataset has 1254 images belonging to 15 classes. here we use class mode 'categorical' because more then 2 classes are available here.

MODEL LOADING:


detection=Sequential()

DESCRIPTION:
Here we use sequential model.The Sequential model API is a way of creating deep learning models where a sequential class is created and model layers are created and added to it.
layers addition
#convolutional layer-1
detection.add(Conv2D(64,(3,3),padding='same',input_shape=(48,48,3)))
detection.add(BatchNormalization())
detection.add(Activation('relu'))
detection.add(MaxPooling2D(pool_size=(2,2)))
detection.add(Dropout(0.25))

#2 -convolutional layer-2
detection.add(Conv2D(128,(5,5),padding='same'))
detection.add(BatchNormalization())
detection.add(Activation('relu'))
detection.add(MaxPooling2D(pool_size=(2,2)))
detection.add(Dropout(0.25))

#3 -convolutional layer-3
detection.add(Conv2D(256,(3,3),padding='same'))
detection.add(BatchNormalization())
detection.add(Activation('relu'))
detection.add(MaxPooling2D(pool_size=(2,2)))
detection.add(Dropout(0.25))

#4 -convolutional layer-4
detection.add(Conv2D(512,(3,3),padding='same'))
detection.add(BatchNormalization())
detection.add(Activation('relu'))
detection.add(MaxPooling2D(pool_size=(2,2)))
detection.add(Dropout(0.25))

#5 -convolutional layer-5
detection.add(Conv2D(512,(3,3),padding='same'))
detection.add(BatchNormalization())
detection.add(Activation('relu'))
detection.add(MaxPooling2D(pool_size=(2,2)))
detection.add(Dropout(0.25))

detection.add(Flatten())
detection.add(Dense(256))
detection.add(BatchNormalization())
detection.add(Activation('relu'))
detection.add(Dropout(0.25))

detection.add(Dense(512))
detection.add(BatchNormalization())
detection.add(Activation('relu'))
detection.add(Dropout(0.25)

detection.add(Dense(15,activation='softmax'))
optimum=Adam(lr=0.005)
#lr-learning rate
detection.compile(optimizer=optimum,loss='categorical_crossentropy',metrics=['accuracy'])

DESCRIPTION:

Here we add various convolutional layers with the Relu activation function (Rectified Linear Unit).We pass the images through the layers more than once for better feature extraction.

Inside the conv2D first perameter show the number of neurons,second show the size of filter/kernal,Input_shape represent here the RGB format of  images.The convolutional layer is then pass to MaxPooling layer,pooliing size is the window size. 

Flatten is used for convert data into 1D form. Dense layer is used for all neurons to the previous layer neurons so it is fully connected layer. Droupout function is use for not taking all the units in the neural network.optimize Adam is used for optimize our data with learning rate.

A metric is a function that is used to judge the performance of your model.  The optimizers are used for improving speed and performance for training a specific model. 

SUMMARY OF ADDED LAYERS:

detection.summary()
# This is used to get all the summary related to model , added layers descriptions.

 OUTPUT:

image 

TRAINING OF MODEL (MODEL CREATION):

MODEL SAVING
ephocs=10
steps_per_epoch=train_generator.n//train_generator.batch_size
steps_per_epoch
validation_steps=validation_generator.n//validation_generator.batch_size
validation_steps
detection.fit(x=train_generator,
                    steps_per_epoch=steps_per_epoch,
                    epochs=ephocs,
                    validation_data=validation_generator,
                    validation_steps=validation_steps)
detection.save('Plant_Disease_Detection.h5')
NOTE:

This is most important part of our model.here we take 10 epochs for train our model. More epochs increase the accuracy and decrease the loss.

The most important thing about this,it run only one time not run this step again and again  because epochs takes time once you run this step do not repeat it again. 

Here we save this model and if we want to use it in future then load this model.

 OUTPUT:

 image

PREDICTION :

PREDICTION #1
from tensorflow.keras.models import load_model
Detection=load_model('Plant_Disease_Detection.h5')
from tensorflow.keras.preprocessing import image
import numpy as np
import matplotlib.pyplot as plt
import cv2
test_img=image.load_img(
"D:\pant\drive\My Drive/test_data/Tomato_healthy/0d515778-61ef-4f0b-ab54-75607c80220f___RS_HL 9745.jpg",target_size=(48,48))
plt.imshow(test_img)
test_img=image.img_to_array(test_img)
test_img=np.expand_dims(test_img,axis=0)
result=Detection.predict(test_img)
a=result.argmax()
# print('a:',a)
classes=train_generator.class_indices
# print(classes)
# print(len(classes))
category=[]
for i in classes:
          category.append(i)
for i in range(len(classes)):
          if(i==a):
              output=category[i]
output 

 OUTPUT:

image 

Tomato_healthy

PREDICTION #2

from tensorflow.keras.models import load_model
Detection=load_model('Plant_Disease_Detection.h5')
from tensorflow.keras.preprocessing import image
import matplotlib.pyplot as plt
import numpy as np
import cv2
test_img=image.load_img(
"D:\pant\drive\MyDrive/test_data/Pepper__bell___healthy/1dd1b153-8ded-439f-8c9e-c9970c67e642___JR_HL 8163.jpg",target_size=(48,48))
plt.imshow(test_img)
test_img=image.img_to_array(test_img)
test_img=np.expand_dims(test_img,axis=0)
result=Detection.predict(test_img)
a=result.argmax()
# print('a',a)
classes=train_generator.class_indices
category=[]
for i in classes:
          category.append(i)
for i in range(len(classes)):
           if(i==a):
                output=category[i]
output  

 

OUTPUT:

Pepper__bell___healthy

pepper image 

THIS PROJECT IS DEVLOPED BY :

NAME: BHOOPENDRA JOSHI  ; ECE ; 6th SEM.

COLLEGE : GLOBAL INSTITUTE OF TECHNOLOGY , JAIPUR

THIS PROJECT IS DEVLOPED DURING "GOEDUHUB ONLINE SUMMER TRAINING IN MACHINE LEARNING , PYTHON AND DEEP LEARNING".

Learn & Improve In-Demand Data Skills Online in this Summer With  These High Quality Courses[Recommended by GOEDUHUB]:-

Best Data Science Online Courses[Lists] on:-

Claim your 10 Days FREE Trial for Pluralsight.

Best Data Science Courses on Datacamp
Best Data Science Courses on Coursera
Best Data Science Courses on Udemy
Best Data Science Courses on Pluralsight
Best Data Science Courses & Microdegrees on Udacity
Best Artificial Intelligence[AI] Courses on Coursera
Best Machine Learning[ML] Courses on Coursera
Best Python Programming Courses on Coursera
Best Artificial Intelligence[AI] Courses on Udemy
Best Python Programming Courses on Udemy

 Important Lists:

Important Lists, Exams & Cutoffs Exams after Graduation PSUs

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy ||  Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 

 

Free Online Directory

...