Plant Leaf Disease Detection Using CNN | Python

KNOWLEDGE DOCTOR
9 Dec 202321:27

Summary

TLDRIn this YouTube tutorial, the host demonstrates how to build a deep learning model for plant disease classification using Python and TensorFlow. They showcase a demo application that predicts leaf diseases from images, utilizing a dataset from Kaggle. The video guides viewers through the process of creating a CNN model, training it with image data augmentation, and compiling it for accuracy. The host then explains how to deploy the model into a web application using Flask, allowing users to upload images for disease prediction. The tutorial is practical, providing step-by-step coding instructions and emphasizing the importance of data balance and model evaluation.

Takeaways

  • 🌟 The video is a tutorial on building a deep learning application for plant disease classification using Python and the Flux web framework.
  • πŸ” The demo application allows users to upload images of plant leaves and receive predictions on diseases like rust and powdery mildew.
  • πŸ“ The tutorial uses a dataset from Kagle, which includes training, testing, and validation sets with images categorized as healthy, rust, or powdery.
  • πŸ’Ύ The data is already split into these sets, so there's no need for additional data partitioning by the user.
  • πŸ”„ The script discusses the importance of data augmentation to increase the dataset size and improve model training, using techniques like image rescaling and flipping.
  • πŸ€– The model used is a Convolutional Neural Network (CNN) due to the image-based nature of the data, with layers including convolution, max pooling, and fully connected layers.
  • πŸ“ˆ The tutorial covers the process of compiling the model with categorical cross-entropy as the loss function, using the Adam optimizer, and training the model with a specified batch size and number of epochs.
  • πŸ“Š The video includes a demonstration of the accuracy and loss curves to evaluate the model's performance and ensure it is neither overfitting nor underfitting.
  • πŸ–ΌοΈ The process of pre-processing new images for prediction involves resizing, normalization, and expanding dimensions to match the model's input requirements.
  • πŸ› οΈ The video concludes with instructions on building a web application using the trained model, including setting up routes and handling image uploads and predictions in a Flask application.
  • πŸ”— The source code and additional resources for the web application are available in the video description or on GitHub for further exploration and use.

Q & A

  • What is the main topic of the video?

    -The main topic of the video is building a deep learning application for plant disease classification using Python and TensorFlow.

  • What is the purpose of the demo application shown in the video?

    -The purpose of the demo application is to classify plant leaf diseases by predicting whether a leaf is healthy, affected by rust, or has powdery mildew based on images.

  • What dataset is used in the video for building the deep learning model?

    -The dataset used is from Kaggle called 'Plant Disease Recognition' which contains images divided into training, testing, and validation sets for three classes: healthy, powdery, and rust.

  • What are the three classes of plant diseases considered in the dataset?

    -The three classes of plant diseases considered are healthy leaves, leaves with powdery mildew, and leaves with rust.

  • Why is data augmentation used in this context?

    -Data augmentation is used to increase the amount of training data by creating new images from existing ones through techniques like rescaling, shearing, zooming in/out, and horizontal flipping, which helps in improving the model's generalization.

  • What type of model is being built in the tutorial?

    -A Convolutional Neural Network (CNN) model is being built in the tutorial, which is suitable for image data.

  • How does the video demonstrate the model's performance?

    -The video demonstrates the model's performance by showing the accuracy on the training and validation sets, as well as by plotting accuracy and loss curves.

  • What activation function is used in the final layer of the CNN model?

    -The Softmax activation function is used in the final layer of the CNN model because it is a multiclass classification problem.

  • How can the trained model be utilized in a web application?

    -The trained model can be saved as a file (e.g., model.h5) and then integrated into a web application using a framework like Flask, where users can upload images to get predictions.

  • What is the significance of the 'pre-process_image' function in the context of the video?

    -The 'pre-process_image' function is significant as it prepares the images for the model by resizing them to the required input size of the CNN, converting them into a NumPy array, and normalizing the pixel values.

  • How does the video ensure the model is not overfitting or underfitting?

    -The video ensures the model is neither overfitting nor underfitting by comparing the accuracy on the training set with the validation set and by showing that there is no significant gap between the two, indicating a well-generalized model.

  • What is the role of the 'secure_file' in the web application code?

    -The 'secure_file' role in the web application code is to prevent unauthorized file access, ensuring that only approved files can be used within the application.

Outlines

00:00

🌿 Introduction to Plant Disease Classification with Deep Learning

The video begins with an introduction to a project on plant disease classification using deep learning. The presenter demonstrates a Python and Flask application that can identify diseases in plant leaves by analyzing images. The application uses a dataset from Kaggle, which contains images of healthy leaves and those affected by powdery mildew and rust. The presenter guides the audience through the process of choosing images, predicting diseases, and emphasizes the importance of building the model from scratch using Python, deep learning, and Flask.

05:00

πŸ” Exploring Data and Setting Up the Deep Learning Model

The second paragraph delves into the details of preparing the dataset for the deep learning model. The presenter explains the process of loading data, checking for balance or imbalance, and creating functions to facilitate data retrieval and counting. The audience is introduced to the concept of data augmentation to increase the dataset's size using an image data generator. The paragraph also covers the initial steps of building a Convolutional Neural Network (CNN) model, including the selection of layers and activation functions, and the importance of compiling the model with the appropriate loss function and optimizer.

10:00

πŸš€ Training the Deep Learning Model and Evaluating Performance

In this segment, the presenter discusses the training process of the deep learning model, including setting the batch size and epochs. The video script mentions the use of a validation set to monitor the model's performance and avoid overfitting. The presenter also explains how to visualize the accuracy and loss curves to assess the model's learning progress. The paragraph concludes with instructions on how to save the trained model for future use and how to test the model with new data by preprocessing the images to match the model's input requirements.

15:02

🌐 Building a Web Application for Disease Prediction with Flask

The fourth paragraph outlines the process of creating a web application using Flask to deploy the trained deep learning model. The presenter describes the structure of the web application, including the creation of folders for static files, templates, and the main application code. The video script provides an overview of the code involved in setting up the routes, handling file uploads, preprocessing images, and using the model to make predictions. The presenter ensures that the application is secure and user-friendly, allowing users to upload images and receive predictions on the fly.

20:03

πŸ“š Conclusion and Testing the Web Application

The final paragraph wraps up the tutorial with a conclusion and a live demonstration of the web application in action. The presenter shows how to run the application on a local server and test it with various images to see the prediction results. The video script emphasizes the successful implementation of the project and encourages viewers to subscribe to the channel for more content. The presenter also hints at future tutorials and thanks the audience for watching.

Mindmap

Keywords

πŸ’‘Deep Learning

Deep Learning is a subset of machine learning that uses artificial neural networks with multiple layers to model and understand complex patterns in data. In the context of the video, deep learning is utilized to classify plant diseases from images, demonstrating its application in image recognition tasks. The script discusses building a deep learning model using Python, which is a common programming language for such applications.

πŸ’‘Flux

Flux, in the context of this video, likely refers to a web framework for building web applications in Python. The script mentions using Flux to create a web application that allows users to upload images and receive predictions from the deep learning model about plant diseases. This showcases how deep learning models can be integrated into web applications for practical use.

πŸ’‘Plant Disease Classification

Plant Disease Classification is the process of identifying the type of disease affecting a plant based on visual or other data. The video's main theme revolves around this concept, where a deep learning model is trained to classify images of plant leaves into categories such as 'healthy', 'powdery mildew', and 'rust'. The script provides a walkthrough of how to predict and classify these diseases using a deep learning model.

πŸ’‘Data Set

A Data Set in this video refers to a collection of data used for training and validating the deep learning model. The script mentions a specific data set from Kaggle called 'Plant Disease Recognition', which contains images categorized into 'healthy', 'powdery', and 'rust' classes. This data set is fundamental to the model's training and evaluation process.

πŸ’‘Model Training

Model Training is the process of teaching a machine learning model to make predictions or decisions based on a dataset. In the script, the process involves using a deep learning model to learn from images of plant diseases. The training process is crucial as it determines the model's ability to accurately classify unseen images.

πŸ’‘Convolutional Neural Network (CNN)

A Convolutional Neural Network, or CNN, is a type of deep learning model that is particularly good at processing data with a grid-like topology, such as images. The script describes building a CNN model for the task of image classification in plant disease detection. CNNs are chosen due to their effectiveness in capturing spatial hierarchies in image data.

πŸ’‘Data Augmentation

Data Augmentation is a technique used to increase the amount of training data by creating modified versions of the original data. In the video script, this technique is used to artificially expand the image dataset by applying transformations like rotation, zoom, and horizontal flip to the images. This helps in improving the model's generalization and reducing overfitting.

πŸ’‘Epoch

An Epoch in machine learning refers to one complete pass through the entire training dataset. The script discusses training the model for a certain number of epochs, which is important as it affects how well the model learns from the data. More epochs can lead to better learning but also increase the risk of overfitting.

πŸ’‘Accuracy

Accuracy in the context of this video refers to the measure of how correctly the model predicts the class of the images. The script mentions achieving a certain percentage of accuracy on the training and validation sets, indicating the performance of the model. High accuracy is a desirable outcome in model training.

πŸ’‘Web Application

A Web Application, as discussed in the script, is a program that allows users to interact with the deep learning model through a web interface. The video demonstrates how to build a web application using the trained model to predict plant diseases from user-uploaded images, showcasing the practical application of deep learning in a user-friendly format.

πŸ’‘Image Preprocessing

Image Preprocessing is a series of operations performed on an image to prepare it for further analysis or modeling. In the script, preprocessing includes resizing images to match the input size expected by the CNN model and normalizing pixel values. This step is essential for ensuring that the input data is in the correct format for the model to process effectively.

Highlights

Introduction to a YouTube tutorial on building a disease classification application for plants using deep learning with Python and TensorFlow.

Demonstration of the application's ability to classify plant diseases from images with high accuracy.

Explanation of the dataset source from Kagle, containing images of plant diseases for training, testing, and validation.

Description of the data set's structure with three classes: healthy, powdery, and rust.

Tutorial on creating a function to load and count the data for balanced or imbalanced assessment.

Use of the ImageDataGenerator for data augmentation to increase the dataset size.

Building a Convolutional Neural Network (CNN) model with TensorFlow's Sequential model.

Inclusion of layers such as Conv2D, MaxPooling, Flatten, and Dense with the Softmax activation function for multi-class classification.

Compilation of the model with categorical cross-entropy loss, accuracy metric, and the Adam optimizer.

Training the model with a batch size of 32 and for 5 epochs, including validation data.

Analysis of the accuracy curve to ensure the model is neither overfitting nor underfitting.

Instructions on saving the trained model for future use.

Process of testing the model with new images and pre-processing them for prediction.

Building a web application using Flask to deploy the model for practical use.

Explanation of the Flask application structure including templates, static files, and routing.

Integration of the pre-trained model into the Flask app for making predictions from uploaded images.

Demonstration of the web application in action, classifying new images of plant diseases accurately.

Encouragement for viewers to subscribe to the channel and look forward to future content.

Transcripts

play00:00

hello everyone and welcome back to my

play00:01

YouTube channel and in this video we are

play00:03

going to be discussing about the planned

play00:04

disease classifications using deep

play00:06

learning and this is De application buil

play00:08

by using Python and flux so let's see

play00:10

the demo application first so first I'm

play00:12

going to click at to choose the file and

play00:14

choose on the picture from my directory

play00:16

testing folder I'm going to select the

play00:18

pictures and click at to open and click

play00:21

at to

play00:22

predict and this is the healthy Leaf

play00:25

healthy leaf plant if I select another

play00:28

photo let's say I'm going to select the

play00:30

photo from the rust and let's select

play00:33

this one click on open and if I predict

play00:35

and you can see here this is nothing but

play00:37

the rust so if I select another

play00:39

photo from my another directory is

play00:42

called powder so this is one kind of dis

play00:46

is plant that's called the powdery and

play00:48

it's also PR it

play00:50

correctly now in this Tut we're going to

play00:52

build this full application from the es

play00:54

course using deep learning Python and

play00:57

flux so without wasting any time let's

play00:59

start the tutorial now so in order to

play01:00

build in the full application we're

play01:02

going be using a data set from kagle

play01:03

that's called the plant disease

play01:05

recognization data set which are

play01:07

containing three files called the train

play01:09

test and the abilitations and each

play01:11

folder containing three files or you can

play01:13

say the number of classes first one is

play01:16

called healthy second one is called the

play01:17

powdery and third one is a rust Now

play01:20

using this data set we going to building

play01:22

our deep learning model and after that

play01:24

we're going to building our web

play01:25

applications using flux so now what we

play01:27

going to do you just need to create your

play01:29

own account on that and after that you

play01:30

can click on the download and download

play01:32

the data set on your directory so well

play01:35

so this is the code for that and I draw

play01:37

the code in my J notebook you can also

play01:39

do it in BS code or the py term or

play01:41

Google Cola itself if you don't have any

play01:43

much more amount of GPU so I going to

play01:45

explain all the code line by line so

play01:47

that you don't need to worry about that

play01:49

what actually happening inside this code

play01:50

and you also building our deep learning

play01:52

model don't worry on that so now I'm

play01:54

going to start the tutorial now and

play01:55

explaining all the code line by line so

play01:57

first what you need to do you need to

play01:58

load the data from our data set folder

play02:02

right and also need to check that if our

play02:03

data is Balan or imbalanced right so

play02:06

first what we can do we can simply

play02:08

create here functions which can actually

play02:10

help us to get the data from here and

play02:13

also do the counting right so for that

play02:15

we to import the O then you need to

play02:17

create here a function that's called da

play02:19

total files and you create here a Lambda

play02:21

function and which one actually creating

play02:22

the list of the each folder each folder

play02:26

and give here the length right so for

play02:28

that you need to give here path let's

play02:30

called the training file healthy the

play02:32

powder and the rust so this is nothing

play02:34

but my classes I mean how many classes

play02:36

are available inside our data set folder

play02:39

so you have the three classes healthy

play02:41

powdery and rust so it simply actually

play02:43

give you the path of that data set we to

play02:45

go in the train then train and healthy

play02:47

right so this is the path for that and

play02:49

again the path for the test file and

play02:51

also the abilitation file simple then

play02:53

what I can do you can simply print it

play02:54

out so you can run the code from here

play02:56

and also you can use the shortcut

play02:58

technique that's called the shift and

play02:59

the the enter in the keyboard shift and

play03:01

the enter and to run the code

play03:03

automatically so you can see number of

play03:06

the healthy images are training set is

play03:08

458 right and you can see the testing

play03:11

set and also the bation set so now let's

play03:13

have a look the data first so let's say

play03:16

look one healthy images so this is the

play03:18

healthy leaf images quite good right so

play03:21

let's see also the r one I mean the

play03:23

affected one so this is the r images

play03:26

with having some spot with having red

play03:28

and the black so what we going to do

play03:31

we're going to Simply classify them

play03:33

which one is a good leap or which one is

play03:35

a bad leap right or which one is a

play03:37

powdery leap right so see we have the

play03:39

limited amount of data and also one more

play03:42

important thing in every video when

play03:44

you're building the machine learning or

play03:46

de learning model we need to divide the

play03:48

data into the train test and split but

play03:51

in this data set you need to do you

play03:52

don't need to do that because the kaggle

play03:54

authority actually do this code again I

play03:56

mean the data set uh the person or the m

play03:59

number actually building the data set he

play04:01

actually do this already right you can

play04:04

see the training set the testing set and

play04:06

the validation set that's me he should

play04:07

divide the data set in the train test

play04:09

and the validation already you don't

play04:11

need to do it you you don't need to do

play04:13

it so that's one plus point for you so

play04:16

now what we can do we can simply do the

play04:19

data argumentation now the question is

play04:22

what is data argumentation and why you

play04:24

need to do that see we have the limited

play04:26

number of data just less than 500 less

play04:29

than 500 so how can we do the data

play04:31

documentation in the Deep learning how

play04:34

can you do that yes we can do it is with

play04:36

the same images using some technique

play04:39

using some technique that's called the

play04:41

image data generator so which one

play04:43

rescale the images which one give you

play04:45

the sharing and we can also zoom in or

play04:48

zoom out and do the horizontal flip and

play04:50

create some new images create some new

play04:54

images in your HEAP memory in your

play04:56

memory in your memory right it don't

play04:58

actually store in your your folder it

play05:00

will actually store it in the memory so

play05:02

let's say I have the 400 images so it

play05:04

will generate let's say 300 images so

play05:06

total 700 images that's mean if you give

play05:10

here the 500 images it will generate

play05:12

more 300 or 400 and create a model for

play05:15

that create a model for that that's

play05:17

called the image data generator or you

play05:19

can say the data argumentation so what

play05:22

you can do you can simply using his

play05:24

image data generator and create a object

play05:26

for that and it will take some parameter

play05:29

to rescale this and after that you're

play05:31

going to give here our image data

play05:35

generator right so we actually creating

play05:36

the object for that now what we can do

play05:38

we can simply run the shell and after

play05:41

that you're going to apply it in our

play05:43

full data set we're going to apply it in

play05:45

our full data set so we have the three

play05:47

folder train test and the validation so

play05:50

we're going to using the training set

play05:52

and the validation set then using this

play05:54

test set you're going to checking for

play05:55

the accuracy you're going to checking

play05:57

for the accuracy so for what you going

play05:59

do we can simply flow from the directory

play06:01

see one more thing flow from the

play06:03

directory how you actually use it how

play06:05

you get one data set which one is

play06:08

already divided into train test and

play06:11

split if you're trying to flow from the

play06:13

directory and also do the data

play06:16

argumentations using this one that's

play06:18

called a flu from directory that's mean

play06:20

when you are passing your data inside

play06:23

your image data generator you need to

play06:25

use this flu from directory so taking

play06:28

the all images from your directory and

play06:30

create and create one extra create one

play06:35

extra uh you can see extra directory

play06:37

forther right in your memory so you can

play06:39

see found 100 322 images belong three

play06:43

classes it have the three classes right

play06:45

it will automatically throw the data

play06:46

from your directory you don't need to

play06:48

use the West you don't need to use the

play06:49

globe don't worry and you can see we got

play06:52

here the 100

play06:54

1,322 images which one the actual images

play06:57

which one the actual images it have also

play06:59

the image data generator images but it's

play07:01

not showing up here it's not showing up

play07:03

it is stor in our memory it is stor in

play07:05

our memory now what we can do we can

play07:07

simply building our deep learning model

play07:09

or you can CNN model now which kind of

play07:12

model are you going using here obviously

play07:14

CNN because this is a image data if it

play07:16

is a numerical data you can use the Ann

play07:19

or the RNN or the lstm right based on

play07:22

your data set if it is if it is time

play07:24

series types of data you can obviously

play07:26

use the lstm or the RNN right so now

play07:28

what you can do you can simply building

play07:30

our deep learning model or can CNN model

play07:32

so we going building here sequential

play07:34

model so there are two types of model

play07:36

are available sequential and another one

play07:38

is called the functional so sequential

play07:41

mean you're going passing the data from

play07:42

one layer to another layer and do the

play07:45

conation operation and do the conation

play07:47

operation so for import the caros do

play07:49

model import the sequential then uted

play07:51

the cony the max pulling layer so there

play07:54

are so many Max pulling Factor actually

play07:56

available Max pulling 2D the average

play07:59

pulling

play07:59

right available right so you can see the

play08:02

flatten so flatten what actually do when

play08:05

you give your data it's a multi

play08:07

dimensional data multi-dimension mean so

play08:09

many dimensions so when you pass it

play08:11

inside your CNN model you need to give

play08:14

it in one kind of vector just a single

play08:16

Vector so that's using the flatten and

play08:19

Dance is for the final layer the input

play08:21

or the output layer right so first you

play08:24

going to create here the sequential we

play08:26

actually give here my kernel uh 32 right

play08:28

3 2 and 3 cross three filter and input

play08:30

shape is 225 225 3 so 225 is mean height

play08:35

and the weight and three is number of

play08:37

channel number of Channel and we have

play08:39

the activation function that's called

play08:40

the reu so reu is actually the formula

play08:42

of re is a Max of Max of Z comma J right

play08:46

Max of Z comma J that mean you're taking

play08:48

the maximum value it will taking the

play08:49

maximum value then what you can do we

play08:51

can simply give you the pulling the max

play08:52

pulling having the pool size of the two

play08:54

it will taking the maximum value for the

play08:56

each full ch right then we going to give

play08:59

here the 64 again 64 activation Rel

play09:02

activation function and add here on

play09:04

maxing layer then finally you going to

play09:05

use here the flatten layer I mean

play09:07

creating here one single vector and give

play09:09

you the dance layer of the 64 and dance

play09:12

layer of the three so three is nothing

play09:13

but my number of classes I mean how many

play09:16

classes are available in your data set

play09:18

we have three classes we have three

play09:19

classes so that's put here three and

play09:21

activation function is soft Max so

play09:23

because this is the multiclass

play09:25

classifications so that's why you give

play09:26

here the soft Max otherwise you can give

play09:28

here

play09:29

we can give you the sigma then need to

play09:32

to also compile the model so before you

play09:34

fitting or you can training the model

play09:36

you need to also compile it see one more

play09:38

important thing we give your law as a

play09:40

categorical cross entropy so when you

play09:43

have multiclass classification types of

play09:46

project it give here the categorical

play09:49

cross enty if it's a binary

play09:51

classification it should be the binary

play09:52

cross enty and Matrix is same accuracy

play09:55

and Optimizer is Adam you can also use

play09:57

gradient Des set S2 gr also you can also

play10:00

do it right so now what you can do you

play10:01

can simply compile it and after that

play10:04

after compiling you need to you need to

play10:06

OKAY model is defined I need to we need

play10:08

to also run this shell so that's why and

play10:10

we need to compile it now and after

play10:13

compiling we need to we need to train

play10:15

the model we need to train the model and

play10:17

you can see the bass size is 16 right

play10:19

you can also give a 32 it's up to you

play10:22

right it's based on your system

play10:24

requirement right you also let's give

play10:25

here the 32 right now and epox is right

play10:28

now five AO is right now five and

play10:31

validation data you can give here the

play10:32

validation from it's coming from the

play10:33

validation generator and the validation

play10:35

b side let's say 16 so if I go here it

play10:38

just have that 20 Imes so it's better we

play10:41

can give you the B size of 16 right

play10:44

because we have the low amount of data

play10:45

so that's why you can also give it 32 or

play10:47

the 64 it's up to you so now what I'm

play10:49

going to do I'm going to Simply run the

play10:50

code and start the epox so what actually

play10:53

epox epox me should go from the forward

play10:55

propagation and again go to the back

play10:57

propagation and actually calculate the

play10:59

weight and based on the weight it will

play11:00

actually minimize this weight minimize

play11:03

the cost function or you can minimize

play11:04

the weight so that's called the eox I

play11:06

mean One For What and one backward and

play11:08

update the weight and update the weight

play11:10

so this is nothing but called the epox

play11:13

so after that what you going do uh we

play11:15

can also generate here one figure for

play11:18

that this is called the accuracy curve

play11:19

so I'll back again when the training

play11:21

part is completed right so well so our

play11:24

model training is completed and you can

play11:27

see here I got here the 90% % accuracy

play11:30

and the validation accuracy is 88% so if

play11:33

I trying to click here to run this shell

play11:35

to floting the accuracy curve and the

play11:37

loss curve and you can see here uh our

play11:40

model is working really fine it's not

play11:42

over fitting or underfitting data uh

play11:44

because it's it don't have any Gap right

play11:47

now right that's when our model is

play11:48

working really very fine so you can also

play11:50

increase your epox in order to also

play11:52

increase your accuracy we got here the

play11:54

90% accuracy you can also increase it by

play11:57

increasing the epoch number right right

play11:59

so now what I can do I can simply going

play12:01

to save the file in a model file model.

play12:04

as5 so that we can use it in the later

play12:06

on or you can also use it in your own

play12:08

devices also so now what we can do we

play12:10

can simply test it out we can simply

play12:12

test it our new data so I'm going taking

play12:14

one image from the rust in our directory

play12:17

then after we testing out right so

play12:19

forther what you need to do you need to

play12:21

also load the images same as it is we do

play12:24

in our data set and after that you need

play12:26

to convert this image into the number

play12:28

ARR so so we going to create here a

play12:30

function which will actually give here

play12:32

the pre-process image so first you

play12:34

loading the images with having the

play12:35

target size of 225 cross 225 because if

play12:38

I go up in our uh CNN model we give here

play12:42

the input shape is 225 2253 so that's

play12:45

why you need to also resize the images

play12:47

in this uh kind of sizes 225 plus 225

play12:51

then we are going to pass it inside our

play12:52

image to AR image to actually do you

play12:56

convert this image into one n AR so that

play12:58

we we can actually normalize it we can

play13:01

normalize it and you can see here it

play13:03

should divide the data into 255 so why

play13:05

255 actually if you see one images gray

play13:09

scale gray scale or the RGB images let's

play13:11

say RGB images it have the value

play13:13

starting from 02 255 so if I'm trying to

play13:16

normalize the data between zero and one

play13:19

we divide the data into big number the

play13:22

maximum number you can see the maximum

play13:24

number so the maximum number is 2555 so

play13:26

that's why divide the data using the 255

play13:29

then we dra the expand Dimensions to the

play13:31

expand the dimension of the data so that

play13:33

we can get our actual prediction value

play13:35

so now what I can do I simply going to

play13:37

run the shell and after that I'm going

play13:39

to click to model. predict and it will

play13:41

give me one predictions right it give me

play13:43

the prediction in the array now in this

play13:46

array we're going to taking the maximum

play13:48

value I mean which one having the

play13:50

maximum number of maximum number of

play13:53

predictions so this is the real

play13:54

predictions so forther what I going do

play13:56

you can simply using here the labels

play13:58

right so that we can also check the

play14:00

levels then simply going to pass here

play14:01

the np. ARG Max and try to see the

play14:04

predictions so our prediction is called

play14:06

R if I go here we actually collect the

play14:08

image from the r folder inside our test

play14:11

see one thing see one thing here we

play14:13

actually train the model using our

play14:15

training set and the validation set we

play14:17

don't use here the testing set so

play14:19

testing set is nothing but for the

play14:21

testing the model to checking the

play14:23

accuracy right that how our model is

play14:26

really working is it able to break the

play14:28

data is new to our data set or not if

play14:31

it's not able to predict it that me it

play14:33

have some problem in your model maybe

play14:35

the problem of the overfitting or the

play14:36

underfitting problem so now what we can

play14:38

do we can simply using this model to

play14:40

building one web applications using flux

play14:43

right so now well you can see here one

play14:46

file is generated it's called the model.

play14:47

as5 so this is our model file you can

play14:50

also open the model file so you can also

play14:53

see the architecture that you built in

play14:55

your CH notebook code so you can see we

play14:57

get here the image size of 2 to 5 cross

play14:59

2 to 5 cross 3 and also having one input

play15:02

layer the convolution layer of 32 right

play15:05

32 kernels and the max ping layer and

play15:07

also Comm 2D two convolution layer and

play15:09

Max ping layer again flatten layer and

play15:11

dance layer the 64 and the dance of

play15:13

three three means our output uh classes

play15:16

you can see number of classes right so

play15:18

this is how you can also visualize your

play15:20

model in in in in the application let's

play15:22

called the nron you can also install the

play15:24

application on window machine then you

play15:25

can see the your model architecture so

play15:28

now do we can simply using this model

play15:30

file and building one application that's

play15:32

called the web applications using flux

play15:34

right so well this is a code for that in

play15:37

know to building the applications using

play15:38

flux so what we actually do here we

play15:41

actually create here a folder that's

play15:42

called athetic so which one containing

play15:44

the CSS and the Javascript file and also

play15:47

one folder that's called the templates

play15:49

and inside that we have our UI that's

play15:52

called the input. HTML and index.html

play15:55

you don't need to worry about the code

play15:56

you can get this code in the video

play15:57

description of the GitHub link you can

play15:59

grab the template file code and Al also

play16:01

the static file code so the main code is

play16:03

actually inside our app.py so let's

play16:07

understand this what actually happening

play16:08

inside this code we first import the W

play16:10

then import the T flow as the T app

play16:12

andai and also the caras do

play16:14

pre-processing images I think you don't

play16:16

need the images you actually using here

play16:18

the car. preprocessing image yet so we

play16:21

do need to do it it then we input here

play16:23

the peel if you using here another

play16:25

method in order to loading the images

play16:27

using peel you can also use this F and

play16:29

also the CB2 just by default actually

play16:31

import it out if you're trying to use it

play16:33

you can also use it later on right then

play16:35

we have our load model and also the

play16:36

render template render template actually

play16:38

help you to render the template inside

play16:40

your template folder so that's why how

play16:42

you creating any flux application you to

play16:44

create a folder that's called the

play16:45

templates and inside that you need to

play16:46

pass your HTML file so this random

play16:49

template is automatically go inside this

play16:51

template folder and it actually fasing

play16:53

the file name which one you are

play16:55

mentioning in your programs then we have

play16:57

actually import here the secure file so

play16:59

that you don't it actually don't anyone

play17:01

cannot use it from the from the devices

play17:04

right so that's why actually you secure

play17:06

the file name right so then we're going

play17:08

to import here the load images and also

play17:10

the image to era that actually do before

play17:11

in our model training path also then

play17:14

what you can do you can simply use here

play17:16

a fla apps that's called fla and

play17:18

parameter as underscore name so using

play17:21

this you can create one flux

play17:23

applications then what you can do you

play17:25

can simply call this main method main

play17:28

method in our app.run function right

play17:30

app. run and we give the de the true and

play17:33

inside our main function to call this

play17:34

app now inside this app we're going to

play17:36

be creating here our API we're going to

play17:38

creating our API so this is the initial

play17:41

route which we actually calling our

play17:42

index.html file this our index.html file

play17:45

so it will call in this functions this

play17:47

is one is Gap method so when you are

play17:49

trying to select one photo and click the

play17:52

predict button it want is get of the

play17:54

post metal because it will actually

play17:56

taking the images from Theory and also

play17:58

do the predictions from our model so

play18:00

that's why the matter should be the get

play18:01

and the post method and after that we

play18:03

going creating one function which are

play18:04

actually taking the images from the

play18:06

users and store it inside the upload

play18:08

folder inside our upload folder you can

play18:10

see so many images are available inside

play18:11

my upload filer uh that we actually do

play18:14

ear in the demo applications so that's

play18:16

why it actually stored inside the upload

play18:17

folder now from the upload folder it

play18:20

will trying to checking the file name

play18:22

and it will do the predictions based on

play18:24

the images right so what you can do we

play18:26

can check for the base file path which

play18:28

one is our uploads then what we can do

play18:30

we can save it inside our upload folder

play18:33

so that we can do the predictions now

play18:35

based on the path we going to do the

play18:37

predictions so we actually create here

play18:38

one function which will actually help us

play18:40

to do the predictions that's called the

play18:42

get results so you can see the get

play18:44

results which one taking the image path

play18:46

so if I go on the model training and go

play18:49

down we you can see we actually creating

play18:51

here one function that's called the

play18:52

pre-process image so which one taking

play18:55

one image which one taking one image

play18:56

path and with having the target size and

play18:58

return here the X so X is nothing but

play19:01

our predictions in a num array format so

play19:03

we just using the same formula in our

play19:06

get result functions which which one Tak

play19:08

on image as a parameter we give her the

play19:11

image Target size and also the convert

play19:13

them into image to the array then expand

play19:15

the dimension and after that we do the

play19:17

predictions after that we do the

play19:19

predictions if I go down you can see the

play19:21

predictions we can get one n by if I

play19:24

give here the prediction is zero right

play19:26

that's when you get here one simple kind

play19:28

of array but how you pass this array

play19:30

inside our np. ARG Max with having the

play19:33

levels then we can do actually actually

play19:35

take our prediction results so if I go

play19:38

here we actually initialize here our

play19:40

levels that's called Z means healthy one

play19:42

mean powdery and two means rust then

play19:44

simply you're going to pass it inside

play19:45

our uh predict functions right predict

play19:48

function after prediction you get it

play19:50

pass it ins our levels NP do ERG Max and

play19:53

we convert them in string so that we

play19:55

don't get any error like it is a non

play19:57

type or the s Mi M Mas this type if you

play20:01

don't get it out so for that we are

play20:03

going to convert them into the string

play20:05

right so that we don't get any error so

play20:08

well so now what you going to do you can

play20:09

simply run the file let's click on here

play20:11

and it will open this file in our local

play20:13

server or you can say local browsers and

play20:16

it will give here on l 1 to

play20:18

7.0.0 5,000 like that right and you can

play20:21

see your model is loaded and now what

play20:23

you can do you can simply click in this

play20:27

link

play20:29

okay so this is the link click here to

play20:31

follow link and this our applications so

play20:34

now what we can do we can simply test it

play20:35

out right well so now I'm going to click

play20:37

to choose the

play20:38

file okay so let's choose the file from

play20:41

the powder redor and you can see the

play20:43

test one so let's select this one and

play20:46

click here to

play20:47

predict okay you can see the power are

play20:50

so let's select another

play20:52

one uh from the rust let's select this

play20:56

one and click to the predict rust it's

play20:59

really working fine right and let's

play21:01

select here another photo from the

play21:03

healthy uh this one and clear to the

play21:06

bate right well so this is really

play21:08

working very fine so that's it for today

play21:10

now hope you enjoy this stud and make

play21:13

sure to subscribe to the channel and

play21:14

don't forget to hit the Bell icon and

play21:16

I'll be back so and

play21:26

bye-bye

Rate This
β˜…
β˜…
β˜…
β˜…
β˜…

5.0 / 5 (0 votes)

Related Tags
Deep LearningPlant DiseasesPythonFlaskImage RecognitionMachine LearningData ScienceWeb DevelopmentCNNAI Applications