Skip to content

Commit c46ac44

Browse files
committed
Added Readme and example server code
1 parent 1939210 commit c46ac44

File tree

7 files changed

+163
-0
lines changed

7 files changed

+163
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Plant-Disease-Detection-using-Deep-learning
2+
3+
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.
4+
5+
You can use the ipynb file to train your model and then you can use that model for prediciting diseases in plants.
6+
7+
8+
## Demo
9+
10+
![output1](https://user-images.githubusercontent.com/78130964/167244940-90f492c3-afa3-4166-8f69-b96789238a32.png)
11+
12+
![output2](https://user-images.githubusercontent.com/78130964/167244958-fb800f61-fd35-4350-bdb8-abe913709bf4.png)
13+
14+
15+
## Note
16+
17+
Put you trained h5 model in app folder and change the label name according to your dataset.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
from flask import Flask, render_template, request
2+
from requests import get #pip install flask
3+
app = Flask(__name__)
4+
5+
6+
import os
7+
import numpy as np
8+
import tensorflow as tf
9+
10+
from tensorflow.compat.v1 import ConfigProto
11+
from tensorflow.compat.v1 import InteractiveSession
12+
config = ConfigProto()
13+
config.gpu_options.per_process_gpu_memory_fraction = 0.2
14+
config.gpu_options.allow_growth = True
15+
session = InteractiveSession(config=config)
16+
17+
# Keras
18+
from tensorflow.keras.applications.resnet50 import preprocess_input
19+
from tensorflow.keras.models import load_model
20+
from tensorflow.keras.preprocessing import image
21+
22+
from werkzeug.utils import secure_filename
23+
24+
MODEL_PATH ='model_inception.h5'
25+
# Load your trained model
26+
model = load_model(MODEL_PATH)
27+
28+
def model_predict(img_path, model):
29+
print(img_path)
30+
img = image.load_img(img_path, target_size=(224, 224))
31+
x = image.img_to_array(img)
32+
x=x/255
33+
x = np.expand_dims(x, axis=0)
34+
35+
preds = model.predict(x)
36+
preds=np.argmax(preds, axis=1)
37+
if preds==0:
38+
preds="Healthy"
39+
elif preds==1:
40+
preds="Powdery"
41+
elif preds==2:
42+
preds="Rust"
43+
44+
return preds
45+
46+
47+
# route
48+
@app.route('/', methods=["GET", "POST"])
49+
def index():
50+
# a=svd.predict(1, 302, 3)
51+
return render_template('index.html')
52+
53+
@app.route('/analyze', methods=["GET", "POST"])
54+
async def analyze():
55+
if request.method == 'POST':
56+
f = request.files['imagefile']
57+
58+
basepath = os.path.dirname(__file__)
59+
file_path = os.path.join(
60+
basepath, 'uploads', secure_filename(f.filename))
61+
f.save(file_path)
62+
63+
preds = model_predict(file_path, model)
64+
result=preds
65+
return render_template('res.html', result=result)
66+
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!!")
67+
if __name__ == "__main__":
68+
app.run(debug=True)
Loading

MachineLearning Projects/Plant Disease Prediction/app/static/style.css

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<!-- Required meta tags -->
6+
<meta charset="utf-8" />
7+
<meta name="viewport" content="width=device-width, initial-scale=1" />
8+
9+
<!-- Bootstrap CSS -->
10+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
11+
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" />
12+
13+
<title>Plant Disease Prediction</title>
14+
<style>
15+
body{
16+
margin: 0%;
17+
padding: 0%;
18+
background-color: bisque;
19+
background-image: url("/static/bg.gif");
20+
background-repeat: repeat-x;
21+
}
22+
.container{
23+
font-family: "cursive";
24+
display: grid;
25+
justify-content: center;
26+
align-items: center;
27+
}
28+
</style>
29+
</head>
30+
31+
<body>
32+
<div class="container my-5">
33+
<form id="analysis-form" method="post" action="analyze" enctype="multipart/form-data">
34+
<label class="add">SELECT IMAGE</label>
35+
<input name="imagefile" id="imagefile" type="file" />
36+
<div>
37+
<button class="btn btn-primary">Analyze</button>
38+
</div>
39+
</form>
40+
</div>
41+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
42+
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
43+
crossorigin="anonymous"></script>
44+
</body>
45+
46+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Result : Plant Disease Prediction</title>
8+
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
9+
integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous" />
10+
11+
<style>
12+
body {
13+
background-color: beige;
14+
}
15+
</style>
16+
</head>
17+
<body>
18+
<div class="container" style="background-color: aquamarine;">
19+
<h2 class="text-center mt-5 py-3">Plant Disease Prediction</h2>
20+
<div class="container">
21+
<p><strong> The plant is classified as: {{result}}</strong></p>
22+
<p>Thanks for using our service</p>
23+
<a href="/">
24+
<button class="btn btn-outline-success mb-5" type="submit"><strong>Go Back</strong></button>
25+
</a>
26+
</div>
27+
</div>
28+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"
29+
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p"
30+
crossorigin="anonymous"></script>
31+
</body>
32+
</html>

0 commit comments

Comments
 (0)