Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-010
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-010
2021-010
Commits
a8e2d6b5
Commit
a8e2d6b5
authored
Nov 23, 2021
by
IT18135862 Wattegedara S. L
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated app.py
parent
41ffb260
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
656 additions
and
15 deletions
+656
-15
flask_orgiC/app.py
flask_orgiC/app.py
+13
-9
flask_orgiC/disease_recognition.ipynb
flask_orgiC/disease_recognition.ipynb
+511
-0
flask_orgiC/disease_recognition.py
flask_orgiC/disease_recognition.py
+104
-0
flask_orgiC/templates/disease.html
flask_orgiC/templates/disease.html
+28
-6
No files found.
flask_orgiC/app.py
View file @
a8e2d6b5
...
...
@@ -18,14 +18,17 @@ def allowed_file(filename):
filename
.
rsplit
(
'.'
,
1
)[
1
]
in
ALLOWED_EXTENSIONS
def
predict
(
file
):
def
predict
_disease
(
file
):
img
=
load_img
(
file
,
target_size
=
IMAGE_SIZE
)
img
=
img_to_array
(
img
)
/
255.0
img
=
np
.
expand_dims
(
img
,
axis
=
0
)
probs
=
img2
.
predict
(
img
)[
0
]
output
=
{
'Healthy'
:
probs
[
0
],
'Sigatoka'
:
probs
[
1
]}
healthy
=
probs
[
0
]
*
100
sigatoka
=
probs
[
1
]
*
100
output
=
{
probs
[
0
],
probs
[
1
]}
return
output
return
probs
...
...
@@ -39,19 +42,20 @@ def template_test():
@
app
.
route
(
'/'
,
methods
=
[
'GET'
,
'POST'
])
def
upload_file
():
def
upload_
desease_
file
():
if
request
.
method
==
'POST'
:
file
=
request
.
files
[
'file'
]
if
file
and
allowed_file
(
file
.
filename
):
filename
=
secure_filename
(
file
.
filename
)
file_path
=
os
.
path
.
join
(
app
.
config
[
'UPLOAD_FOLDER'
],
filename
)
file
.
save
(
file_path
)
output
=
predict
(
file_path
)
file_path1
=
os
.
path
.
join
(
app
.
config
[
'UPLOAD_FOLDER'
],
filename
)
file
.
save
(
file_path1
)
output
=
predict_disease
(
file_path1
)
# output = {probs[0],probs[1]}
healthy
=
output
[
0
]
*
100
sigatoka
=
output
[
1
]
*
100
return
render_template
(
"disease.html"
,
label
=
output
,
imagesource
=
file_path
)
return
render_template
(
"disease.html"
,
label1
=
healthy
,
label2
=
sigatoka
,
imagesource
=
file_path1
)
@
app
.
route
(
'/uploads/<filename>'
)
...
...
flask_orgiC/disease_recognition.ipynb
0 → 100644
View file @
a8e2d6b5
This diff is collapsed.
Click to expand it.
flask_orgiC/disease_recognition.py
0 → 100644
View file @
a8e2d6b5
# -*- coding: utf-8 -*-
"""disease recognition.ipynb
Automatically generated by Colaboratory.
Original file is located at
https://colab.research.google.com/drive/1KZ0kUs19r-B0Rs7f0N5oz5nzH4y9NkUd
"""
import
cv2
import
os
data_path
=
'/content/drive/MyDrive/CDAP/Banana Leaf Disease'
categories
=
os
.
listdir
(
data_path
)
labels
=
[
i
for
i
in
range
(
len
(
categories
))]
label_dict
=
dict
(
zip
(
categories
,
labels
))
print
(
label_dict
)
print
(
categories
)
print
(
labels
)
img_size
=
224
data
=
[]
target
=
[]
for
category
in
categories
:
folder_path
=
os
.
path
.
join
(
data_path
,
category
)
img_names
=
os
.
listdir
(
folder_path
)
for
img_name
in
img_names
:
img_path
=
os
.
path
.
join
(
folder_path
,
img_name
)
img
=
cv2
.
imread
(
img_path
)
try
:
resized
=
cv2
.
resize
(
img
,(
img_size
,
img_size
))
data
.
append
(
resized
)
target
.
append
(
label_dict
[
category
])
except
Exception
as
e
:
print
(
'Exception:'
,
e
)
import
numpy
as
np
data
=
np
.
array
(
data
)
/
255.0
data
=
np
.
reshape
(
data
,(
data
.
shape
[
0
],
img_size
,
img_size
,
3
))
target
=
np
.
array
(
target
)
from
keras.utils
import
np_utils
new_target
=
np_utils
.
to_categorical
(
target
)
from
keras.models
import
Sequential
from
keras.layers
import
Dense
,
Activation
,
Flatten
,
Dropout
from
keras.layers
import
Conv2D
,
MaxPooling2D
from
keras.callbacks
import
ModelCheckpoint
model
=
Sequential
()
model
.
add
(
Conv2D
(
200
,(
3
,
3
),
input_shape
=
data
.
shape
[
1
:]))
model
.
add
(
Activation
(
'relu'
))
model
.
add
(
MaxPooling2D
(
pool_size
=
(
2
,
2
)))
model
.
add
(
Conv2D
(
100
,(
3
,
3
)))
model
.
add
(
Activation
(
'relu'
))
model
.
add
(
MaxPooling2D
(
pool_size
=
(
2
,
2
)))
model
.
add
(
Flatten
())
model
.
add
(
Dropout
(
0.5
))
model
.
add
(
Dense
(
50
,
activation
=
'relu'
))
model
.
add
(
Dense
(
2
,
activation
=
'softmax'
))
model
.
compile
(
loss
=
'categorical_crossentropy'
,
optimizer
=
'adam'
,
metrics
=
[
'accuracy'
])
model
.
summary
()
from
sklearn.model_selection
import
train_test_split
train_data
,
test_data
,
train_target
,
test_target
=
train_test_split
(
data
,
new_target
,
test_size
=
0.2
)
train_data
.
shape
train_target
.
shape
test_target
.
shape
history
=
model
.
fit
(
train_data
,
train_target
,
epochs
=
75
,
validation_split
=
0.2
)
model
.
save
(
'/content/drive/MyDrive/CDAP/disease_modelrp.h5'
)
from
matplotlib
import
pyplot
as
plt
N
=
75
plt
.
style
.
use
(
"ggplot"
)
plt
.
figure
()
plt
.
plot
(
np
.
arange
(
0
,
N
),
history
.
history
[
"loss"
],
label
=
"train_loss"
)
plt
.
plot
(
np
.
arange
(
0
,
N
),
history
.
history
[
"val_loss"
],
label
=
"val_loss"
)
plt
.
plot
(
np
.
arange
(
0
,
N
),
history
.
history
[
"accuracy"
],
label
=
"train_acc"
)
plt
.
plot
(
np
.
arange
(
0
,
N
),
history
.
history
[
"val_accuracy"
],
label
=
"val_acc"
)
plt
.
title
(
"Training Loss and Accuracy"
)
plt
.
xlabel
(
"Epoch #"
)
plt
.
ylabel
(
"Loss/Accuracy"
)
plt
.
legend
(
loc
=
"center right"
)
plt
.
savefig
(
"CNN_Model"
)
\ No newline at end of file
flask_orgiC/templates/disease.html
View file @
a8e2d6b5
...
...
@@ -36,33 +36,55 @@
</form>
-->
</div>
<p
style=
"margin-bottom:2cm;"
></p>
<p
style=
"margin-bottom:2cm;"
></p>
<div
class=
"row"
>
<div
class=
"col-8"
>
<div
class=
"page-header"
>
<h3
id=
"tables"
>
Result
</h3>
</div>
</div>
<div
class=
"col-4"
>
col-4
</div>
</div>
<div
class=
"row"
>
<div
class=
"col-lg-4"
>
<div
class=
"page-header"
>
<h3
id=
"tables"
>
Result
</h3>
</div>
<div
class=
"bs-component"
>
<img
width=
"400"
height=
"400"
src=
"{{imagesource}}"
/>
<table
class=
"table table-hover"
>
<tr
class=
"table-active"
>
<!-- <th scope="col">Image</th> -->
<th
scope=
"col"
>
Predict
</th>
</tr>
<tr>
{% if label %}
<th
scope=
"row"
>
<img
width=
"224"
height=
"224"
src=
"{{imagesource}}"
/>
</th>
<th
scope=
"row"
>
Leaf Type
</th>
<th
scope=
"row"
>
Accuracy
</th>
</tr>
<tr>
<td>
Prediction :
<i>
{{label }}
</i></td>
<td>
Healthy :
</td>
<td>
Sigatoka :
</td>
{% endif %}
</tr>
<tr>
<td><i>
{{label1 }}
</i></td>
<td><i>
{{label2 }}
</i></td>
</tr>
</table>
</div>
</div>
</div>
</div>
<p>
</p>
<p>
</p>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment