EnYa32 commited on
Commit
6ecdd4b
Β·
verified Β·
1 Parent(s): 9b60d1c

Upload 4 files

Browse files
.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
+ src/grape_cnn_final_optionA.keras filter=lfs diff=lfs merge=lfs -text
src/GrapeVineDataClassification (4).ipynb ADDED
The diff for this file is too large to render. See raw diff
 
src/app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py --- Grapevine Leaf Disease Classifier using CNN (without Transfer Learning)
2
+ import streamlit as st
3
+ import numpy as np
4
+ from PIL import Image
5
+ import tensorflow as tf
6
+ from tensorflow.keras.models import load_model
7
+ import warnings
8
+ warnings.filterwarnings("ignore", category=DeprecationWarning)
9
+
10
+
11
+ # ------------------ SETTINGS ------------------
12
+ MODEL_PATH = "grape_cnn_final_optionA.keras" # CNN model (trained from scratch)
13
+ IMG_SIZE = (224, 224) # Based on your training setup
14
+
15
+ # Class labels (same order as during training)
16
+ CLASS_NAMES = [
17
+ "Black Rot",
18
+ "Esca (Black Measles)",
19
+ "Leaf Blight (Isariopsis Leaf Spot)",
20
+ "Healthy"
21
+ ]
22
+
23
+ # ------------------ LOAD MODEL ------------------
24
+ @st.cache_resource
25
+ def load_model_cached():
26
+ return load_model(MODEL_PATH)
27
+
28
+ model = load_model_cached()
29
+
30
+ # ------------------ IMAGE PREPROCESSING ------------------
31
+ def preprocess_image(image: Image.Image) -> np.ndarray:
32
+ image = image.convert("RGB")
33
+ image = image.resize(IMG_SIZE)
34
+ img_array = np.array(image) / 255.0 # Normalization (used during training)
35
+ return np.expand_dims(img_array, axis=0)
36
+
37
+ # ------------------ PREDICTION ------------------
38
+ def predict(image: Image.Image):
39
+ processed_img = preprocess_image(image)
40
+ preds = model.predict(processed_img)
41
+ probs = tf.nn.softmax(preds[0]).numpy() # In case final layer used raw logits
42
+ top_idx = np.argmax(probs)
43
+ return CLASS_NAMES[top_idx], probs[top_idx], probs
44
+
45
+ # ------------------ STREAMLIT UI ------------------
46
+ st.set_page_config(page_title="Grapevine CNN Classifier (No Transfer Learning)", layout="centered")
47
+
48
+ st.title("πŸ‡ Grapevine Leaf Disease Classifier (CNN – No Transfer Learning)")
49
+ st.write(
50
+ "This app uses your custom Convolutional Neural Network trained **from scratch** "
51
+ "to classify grapevine leaf images into disease categories."
52
+ )
53
+
54
+ # --- Model Info ---
55
+ st.sidebar.header("πŸ”§ Model Details")
56
+ st.sidebar.write(f"**Model file:** `{MODEL_PATH}`")
57
+ st.sidebar.write(f"**Input size:** {IMG_SIZE[0]} Γ— {IMG_SIZE[1]}")
58
+ st.sidebar.write("**Class labels:**")
59
+ for cls in CLASS_NAMES:
60
+ st.sidebar.write(f"- {cls}")
61
+
62
+ # --- File Upload ---
63
+ uploaded_file = st.file_uploader("πŸ“€ Upload a grapevine leaf image", type=["jpg", "jpeg", "png"])
64
+
65
+ if uploaded_file is not None:
66
+ image = Image.open(uploaded_file)
67
+ st.image(image, caption="πŸ“Έ Uploaded Image", use_container_width=True)
68
+
69
+ if st.button("πŸ” Predict Disease"):
70
+ with st.spinner("Analyzing image..."):
71
+ top_class, top_prob, probabilities = predict(image)
72
+
73
+ st.subheader("πŸ”Ž Prediction Result")
74
+ st.write(f"**Predicted Disease:** `{top_class}`")
75
+ st.write(f"**Confidence:** {top_prob:.2%}")
76
+
77
+ st.subheader("πŸ“Š Probability per Class")
78
+ for cls, prob in zip(CLASS_NAMES, probabilities):
79
+ st.write(f"- **{cls}** β†’ {prob:.2%}")
80
+ else:
81
+ st.info("Please upload a grapevine leaf image to start the prediction.")
src/grape_cnn_final_optionA.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:49d8848f7a64705616ca9063aaef1915d0b54bb5baa48ec21e41acd406bd07db
3
+ size 415432512
src/grape_training_history.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:23cc08c29531d54ed57aaf40537dcc8793b017b66340b4dfa2c481961bd4c386
3
+ size 1222