Upload 10 files
Browse files- .gitattributes +1 -0
- 1/fingerprint.pb +3 -0
- 1/keras_metadata.pb +3 -0
- 1/saved_model.pb +3 -0
- 1/variables/variables.data-00000-of-00001 +3 -0
- 1/variables/variables.index +0 -0
- app.py +72 -0
- requirements.txt +13 -0
- runtime.txt +1 -0
- streamlit.py +77 -0
- trained model/best_model.h5 +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
1/variables/variables.data-00000-of-00001 filter=lfs diff=lfs merge=lfs -text
|
1/fingerprint.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:169ddeaf53bb0d5a2e5bc95f10451649b077733685c7336135aea9628ed5fd8d
|
3 |
+
size 59
|
1/keras_metadata.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bd190c796996520cb6535f5301d9a57316589f3f9c5a930b9d93a3f0c6dbb7ed
|
3 |
+
size 32271
|
1/saved_model.pb
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c5e3d8b097a0631279608b125f44b7fd3b9e3f4927af50b0c5421442f3269721
|
3 |
+
size 276478
|
1/variables/variables.data-00000-of-00001
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:25e2b37e304e0e6100d4c54e014448d03636166fbb484432547d18244f6361d2
|
3 |
+
size 2220878
|
1/variables/variables.index
ADDED
Binary file (3.39 kB). View file
|
|
app.py
ADDED
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import numpy as np
|
3 |
+
from PIL import Image
|
4 |
+
from keras.models import load_model
|
5 |
+
|
6 |
+
# Load the pre-trained model for banana ripeness detection
|
7 |
+
banana_model = load_model("trained model/best_model.h5")
|
8 |
+
|
9 |
+
# Define class names for the banana disease detection
|
10 |
+
class_names_disease = {
|
11 |
+
0: 'BUNCHY_TOP',
|
12 |
+
1: 'CORDANA',
|
13 |
+
2: 'PANAMA',
|
14 |
+
3: 'SIGATOKA'
|
15 |
+
}
|
16 |
+
|
17 |
+
# Define class names for the banana ripeness detection
|
18 |
+
class_names_ripeness = ["Banana_G1", "Banana_G2", "Rotten"]
|
19 |
+
model = load_model("trained model/best_model.h5")
|
20 |
+
|
21 |
+
def preprocess_image(image):
|
22 |
+
img = Image.open(image)
|
23 |
+
img = img.resize((256, 256)) # Resize the image to the input size of the model
|
24 |
+
img_array = np.array(img)
|
25 |
+
img_array = img_array / 255.0 # Normalize the pixel values
|
26 |
+
img_array = np.expand_dims(img_array, axis=0) # Add batch dimension
|
27 |
+
return img_array
|
28 |
+
|
29 |
+
|
30 |
+
def predict(image):
|
31 |
+
img_array = preprocess_image(image)
|
32 |
+
predictions = model.predict(img_array)
|
33 |
+
predicted_class = np.argmax(predictions)
|
34 |
+
predicted_label = class_names_disease[predicted_class]
|
35 |
+
return predicted_label
|
36 |
+
|
37 |
+
def predict_disease(uploaded_file):
|
38 |
+
if uploaded_file is not None:
|
39 |
+
predicted_label = predict(uploaded_file)
|
40 |
+
return predicted_label
|
41 |
+
|
42 |
+
|
43 |
+
def predict_ripeness(image):
|
44 |
+
img_array = preprocess_image(image)
|
45 |
+
predictions = banana_model.predict(img_array)
|
46 |
+
predicted_class = np.argmax(predictions)
|
47 |
+
predicted_label = class_names_ripeness[predicted_class]
|
48 |
+
return predicted_label
|
49 |
+
|
50 |
+
def main():
|
51 |
+
st.title("Banana Analysis App")
|
52 |
+
st.write("Choose an option to analyze bananas")
|
53 |
+
|
54 |
+
# Options for banana analysis
|
55 |
+
analysis_option = st.radio("Choose an option", ["Banana Disease Detection", "Banana Ripeness Detection"])
|
56 |
+
|
57 |
+
# File uploader
|
58 |
+
uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
|
59 |
+
|
60 |
+
if uploaded_file is not None:
|
61 |
+
# Display the uploaded image
|
62 |
+
st.image(uploaded_file, caption='Uploaded Image', use_column_width=True)
|
63 |
+
if st.button("Analyze"):
|
64 |
+
if analysis_option == "Banana Disease Detection":
|
65 |
+
predicted_label = predict_disease(uploaded_file)
|
66 |
+
st.success(f"Predicted disease: {predicted_label}")
|
67 |
+
elif analysis_option == "Banana Ripeness Detection":
|
68 |
+
predicted_label = predict_ripeness(uploaded_file)
|
69 |
+
st.success(f"Predicted ripeness: {predicted_label}")
|
70 |
+
|
71 |
+
if __name__ == '__main__':
|
72 |
+
main()
|
requirements.txt
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Flask==2.0.2
|
2 |
+
Flask-PyMongo==2.3.0
|
3 |
+
Werkzeug==2.2.2
|
4 |
+
requests==2.26.0
|
5 |
+
pandas==1.3.4
|
6 |
+
tensorflow-cpu==2.7.0
|
7 |
+
opencv-python==4.5.4.58
|
8 |
+
keras==2.7.0
|
9 |
+
Keras-Preprocessing==1.1.2
|
10 |
+
twilio==7.2.0
|
11 |
+
Pillow==8.4.0
|
12 |
+
protobuf==3.20.*
|
13 |
+
streamlit==1.34.0
|
runtime.txt
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
python-3.8
|
streamlit.py
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
+
os.environ["TF_USE_LEGACY_KERAS"] = "1"
|
3 |
+
|
4 |
+
from keras.models import load_model
|
5 |
+
import streamlit as st
|
6 |
+
import numpy as np
|
7 |
+
from io import BytesIO
|
8 |
+
from PIL import Image
|
9 |
+
import tensorflow as tf
|
10 |
+
|
11 |
+
st.markdown(
|
12 |
+
"""
|
13 |
+
<style>
|
14 |
+
.reportview-container {
|
15 |
+
background: url('./bg.jpg');
|
16 |
+
background-size: cover;
|
17 |
+
}
|
18 |
+
</style>
|
19 |
+
""",
|
20 |
+
unsafe_allow_html=True
|
21 |
+
)
|
22 |
+
|
23 |
+
st.markdown("# Bananas Maturity Classification ")
|
24 |
+
st.sidebar.markdown("# Main Page")
|
25 |
+
|
26 |
+
MODEL = load_model("./1")
|
27 |
+
|
28 |
+
CLASS_NAMES = ["Banana_G1", "Banana_G2", "Rotten"]
|
29 |
+
|
30 |
+
|
31 |
+
def read_file_as_image(data) -> np.ndarray:
|
32 |
+
image = np.array(Image.open(BytesIO(data)))
|
33 |
+
return image
|
34 |
+
|
35 |
+
|
36 |
+
def predict(
|
37 |
+
file,
|
38 |
+
):
|
39 |
+
image = read_file_as_image(file.read())
|
40 |
+
shape = image.shape
|
41 |
+
img_batch = np.expand_dims(image, 0)
|
42 |
+
# resize image to (256,256,3)
|
43 |
+
img_batch = tf.image.resize(img_batch, (256, 256))
|
44 |
+
prediction = MODEL.predict(img_batch)
|
45 |
+
predicted_class = CLASS_NAMES[np.argmax(prediction[0])]
|
46 |
+
confidence = np.max(prediction[0])
|
47 |
+
if predicted_class == "Banana_G2":
|
48 |
+
predicted_class = "Green Banana- not ripen"
|
49 |
+
elif predicted_class == "Banana_G1":
|
50 |
+
predicted_class = "Mature Banana -ripen"
|
51 |
+
else:
|
52 |
+
predicted_class = "Rotten Banana"
|
53 |
+
return {
|
54 |
+
'class': predicted_class,
|
55 |
+
'confidence': float(confidence)
|
56 |
+
}
|
57 |
+
|
58 |
+
|
59 |
+
st.write("Upload an image or capture one with your camera")
|
60 |
+
|
61 |
+
option = st.selectbox("Choose an option", ["Upload Image", "Capture Image"])
|
62 |
+
|
63 |
+
if option == "Upload Image":
|
64 |
+
uploaded_file = st.file_uploader("Choose an image", type=["jpg", "jpeg", "png"])
|
65 |
+
if uploaded_file is not None:
|
66 |
+
result = predict(uploaded_file)
|
67 |
+
predicted_class = result['class']
|
68 |
+
confidence = result['confidence']
|
69 |
+
if predicted_class == "Green Banana- not ripen":
|
70 |
+
color = 'green'
|
71 |
+
elif predicted_class == "Mature Banana -ripen":
|
72 |
+
color = 'yellow'
|
73 |
+
else:
|
74 |
+
color = 'red'
|
75 |
+
st.markdown(
|
76 |
+
f'<p style="color:{color}; font-size:24px;">Predicted class: {predicted_class}, Confidence: {confidence:.2f}</p>',
|
77 |
+
unsafe_allow_html=True)
|
trained model/best_model.h5
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:592009892209cc32196e69c98094ab96beef82019a53d535c59343b181256b98
|
3 |
+
size 81761440
|