Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions MachineLearning Projects/Plant Disease Prediction/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Plant-Disease-Detection-using-Deep-learning

Image based detection of plant diseases is an essential research topic as it may prove benefits in monitoring large fields of crops, and thus detect the symptoms of diseases as soon as they appear on plant leaves.

You can use the ipynb file to train your model and then you can use that model for prediciting diseases in plants.


## Demo

![output1](https://user-images.githubusercontent.com/78130964/185595235-93111ca6-4277-4456-b0b8-a762c4bb41a0.png)


![output2](https://user-images.githubusercontent.com/78130964/167244958-fb800f61-fd35-4350-bdb8-abe913709bf4.png)


## Note

Put you trained h5 model in app folder and change the label name according to your dataset.
68 changes: 68 additions & 0 deletions MachineLearning Projects/Plant Disease Prediction/app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
from flask import Flask, render_template, request
from requests import get #pip install flask
app = Flask(__name__)


import os
import numpy as np
import tensorflow as tf

from tensorflow.compat.v1 import ConfigProto
from tensorflow.compat.v1 import InteractiveSession
config = ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.2
config.gpu_options.allow_growth = True
session = InteractiveSession(config=config)

# Keras
from tensorflow.keras.applications.resnet50 import preprocess_input
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing import image

from werkzeug.utils import secure_filename

MODEL_PATH ='model_inception.h5'
# Load your trained model
model = load_model(MODEL_PATH)

def model_predict(img_path, model):
print(img_path)
img = image.load_img(img_path, target_size=(224, 224))
x = image.img_to_array(img)
x=x/255
x = np.expand_dims(x, axis=0)

preds = model.predict(x)
preds=np.argmax(preds, axis=1)
if preds==0:
preds="Healthy"
elif preds==1:
preds="Powdery"
elif preds==2:
preds="Rust"

return preds


# route
@app.route('/', methods=["GET", "POST"])
def index():
# a=svd.predict(1, 302, 3)
return render_template('index.html')

@app.route('/analyze', methods=["GET", "POST"])
async def analyze():
if request.method == 'POST':
f = request.files['imagefile']

basepath = os.path.dirname(__file__)
file_path = os.path.join(
basepath, 'uploads', secure_filename(f.filename))
f.save(file_path)

preds = model_predict(file_path, model)
result=preds
return render_template('res.html', result=result)
return render_template('res.html', result="Sorry!! we're not able to find any relevent result for your image, please check the image and retry!!")
if __name__ == "__main__":
app.run(debug=True)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<!DOCTYPE html>
<html lang="en">

<head>
<!-- Required meta tags -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />

<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" />

<title>Plant Disease Prediction</title>
<style>
body{
margin: 0%;
padding: 0%;
background-color: bisque;
<! --background-image: url("/static/bg.gif");-->
background-repeat: repeat-x;
}
.container{
font-family: "cursive";
display: grid;
justify-content: center;
align-items: center;
}
</style>
</head>

<body>
<div class="container my-5">
<form id="analysis-form" method="post" action="analyze" enctype="multipart/form-data">
<label class="add">SELECT IMAGE</label>
<input name="imagefile" id="imagefile" type="file" />
<div>
<button class="btn btn-primary">Analyze</button>
</div>
</form>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
</body>

</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Result : Plant Disease Prediction</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" />

<style>
body {
background-color: beige;
}
</style>
</head>
<body>
<div class="container" style="background-color: aquamarine;">
<h2 class="text-center mt-5 py-3">Plant Disease Prediction</h2>
<div class="container">
<p><strong> The plant is classified as: {{result}}</strong></p>
<p>Thanks for using our service</p>
<a href="/">
<button class="btn btn-outline-success mb-5" type="submit"><strong>Go Back</strong></button>
</a>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
crossorigin="anonymous"></script>
</body>
</html>