joyjitroy commited on
Commit
9643318
Β·
verified Β·
1 Parent(s): 38e20df

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +91 -11
README.md CHANGED
@@ -19,18 +19,59 @@ Farmers and agronomists often spend countless hours identifying seedlings, weeds
19
  This model leverages **Deep Learning and Computer Vision** to automatically recognize plant species from seedling images β€”
20
  helping accelerate early-stage crop monitoring and enabling precision agriculture.
21
 
 
 
 
 
22
  ---
23
 
24
  ## πŸ€– Model Details
25
  - **Model Type:** CNN-based Image Classifier
26
  - **Framework:** TensorFlow / Keras
27
- - **Dataset:** Plant Seedlings Dataset (12 plant categories)
28
- - **Input:** RGB image of a seedling
 
29
  - **Output:** Predicted plant species label
30
 
31
  ---
32
 
33
- ## 🌾 Why It Matters
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
  βœ… Reduces manual effort in plant identification
35
  βœ… Boosts accuracy and consistency in seedling detection
36
  βœ… Supports sustainable, data-driven agriculture
@@ -38,21 +79,60 @@ helping accelerate early-stage crop monitoring and enabling precision agricultur
38
 
39
  πŸ“˜ **Full Source Notebook:**
40
  The complete training and evaluation notebook is available on GitHub:
41
- πŸ‘‰ [View on GitHub](https://github.com/joyjitroy/Machine_Learning/blob/main/Bank_Customer_Churn_Prediction_using_Artificial_Neural_Networks.ipynb)
 
42
 
43
  ---
44
 
45
  ## πŸš€ Example Usage
46
  ```python
 
 
 
 
 
47
  from tensorflow.keras.models import load_model
48
  from tensorflow.keras.preprocessing import image
49
- import numpy as np
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
 
51
- model = load_model("plant_seedlings_model.h5")
 
52
 
53
- img = image.load_img("seedling.jpg", target_size=(128, 128))
54
- x = image.img_to_array(img)
55
- x = np.expand_dims(x, axis=0) / 255.0
 
 
 
56
 
57
- pred = np.argmax(model.predict(x), axis=1)
58
- print("Predicted plant category:", pred)
 
 
 
 
19
  This model leverages **Deep Learning and Computer Vision** to automatically recognize plant species from seedling images β€”
20
  helping accelerate early-stage crop monitoring and enabling precision agriculture.
21
 
22
+ **Objective**
23
+ The aim of this project is to build a **Convolutional Neural Network (CNN)** to classify plant seedlings into their respective categories,
24
+ reducing manual work and enabling scalable, automated monitoring.
25
+
26
  ---
27
 
28
  ## πŸ€– Model Details
29
  - **Model Type:** CNN-based Image Classifier
30
  - **Framework:** TensorFlow / Keras
31
+ - **Dataset:** Aarhus Plant Seedlings Dataset *(12 plant species)*
32
+ - **Data Files:** `images.npy` (image array), `Labels.csv` (species labels)
33
+ - **Input:** RGB image of a seedling (128 Γ— 128)
34
  - **Output:** Predicted plant species label
35
 
36
  ---
37
 
38
+ ## πŸ“Š Data Dictionary
39
+ | Feature / File | Description |
40
+ |-----------------------|-----------------------------------------------------------------------------|
41
+ | `images.npy` | Numpy array containing all seedling images |
42
+ | `Labels.csv` | CSV file containing labels for each image |
43
+ | `label` | Column specifying plant species name |
44
+ | Image Shape | 128 Γ— 128 Γ— 3 RGB |
45
+ | Classes | 12 species |
46
+
47
+ ---
48
+
49
+ ## 🌿 List of Species
50
+ - Black-grass
51
+ - Charlock
52
+ - Cleavers
53
+ - Common Chickweed
54
+ - Common Wheat
55
+ - Fat Hen
56
+ - Loose Silky-bent
57
+ - Maize
58
+ - Scentless Mayweed
59
+ - Shepherds Purse
60
+ - Small-flowered Cranesbill
61
+ - Sugar beet
62
+
63
+ ---
64
+
65
+ ## 🌿 Problem Context
66
+ In recent times, the field of agriculture has been in urgent need of modernizing, since the amount of manual work people need to put in to check if plants are growing correctly is still highly extensive.
67
+ Despite several advances in agricultural technology, people working in the agricultural industry still need to have the ability to sort and recognize different plants and weeds, which takes a lot of time and effort in the long term.
68
+
69
+ The potential is ripe for this trillion-dollar industry to be greatly impacted by technological innovations that cut down on the requirement for manual labor. This is where **Artificial Intelligence** can truly benefit the sector.
70
+ Faster and more accurate seedling identification can lead to better crop yields, allow workers to focus on higher-order decision-making, and promote more sustainable agricultural practices.
71
+
72
+ ---
73
+
74
+ ## 🌟 Why It Matters
75
  βœ… Reduces manual effort in plant identification
76
  βœ… Boosts accuracy and consistency in seedling detection
77
  βœ… Supports sustainable, data-driven agriculture
 
79
 
80
  πŸ“˜ **Full Source Notebook:**
81
  The complete training and evaluation notebook is available on GitHub:
82
+ πŸ‘‰ [View on GitHub](https://github.com/joyjitroy/Machine_Learning/blob/main/Plant_Seeding_Classification_using_CNN.ipynb)
83
+
84
 
85
  ---
86
 
87
  ## πŸš€ Example Usage
88
  ```python
89
+ # Inference example aligned to your dataset schema
90
+ # Files: Data/images.npy (H, W, 3) images, Data/Labels.csv (columns: filename,label)
91
+
92
+ import numpy as np
93
+ import pandas as pd
94
  from tensorflow.keras.models import load_model
95
  from tensorflow.keras.preprocessing import image
96
+ from pathlib import Path
97
+
98
+ # ---- Paths & constants (match your training setup) ----
99
+ IMAGES_NPY = "Data/images.npy" # preprocessed array of images
100
+ LABELS_CSV = "Data/Labels.csv" # has a 'label' column with species names
101
+ MODEL_PATH = "plant_seedlings_cnn.keras" # or "plant_seedlings_model.h5"
102
+ IMAGE_SIZE = (128, 128) # use the SAME size you trained with
103
+ SCALE = 1.0 / 255.0 # same normalization as training
104
+
105
+ # ---- Load model and class names (from Labels.csv) ----
106
+ model = load_model(MODEL_PATH)
107
+
108
+ labels_df = pd.read_csv(LABELS_CSV)
109
+ # Get stable, reproducible class order (sorted unique labels)
110
+ class_names = sorted(labels_df["label"].unique())
111
+ class_to_idx = {c: i for i, c in enumerate(class_names)}
112
+ idx_to_class = {i: c for c, i in class_to_idx.items()}
113
+
114
+ # ---------- Option A: Predict on an external image file ----------
115
+ def predict_image(img_path: str) -> tuple[str, float]:
116
+ """Predict species from a raw image file."""
117
+ img = image.load_img(img_path, target_size=IMAGE_SIZE)
118
+ x = image.img_to_array(img) * SCALE
119
+ x = np.expand_dims(x, axis=0) # (1, H, W, 3)
120
+ prob = model.predict(x, verbose=0)[0] # shape: (num_classes,)
121
+ pred_idx = int(np.argmax(prob))
122
+ return idx_to_class[pred_idx], float(prob[pred_idx])
123
 
124
+ species, conf = predict_image("seedling.jpg")
125
+ print(f"Predicted species: {species} | confidence: {conf:.4f}")
126
 
127
+ # ---------- Option B: Predict from your prepacked dataset ----------
128
+ # Assumes images.npy already contains images at IMAGE_SIZE and same scaling is required.
129
+ # If images.npy is raw uint8, multiply by SCALE; if already scaled, set SCALE=1.0 above.
130
+ images = np.load(IMAGES_NPY) # expected shape: (N, H, W, 3)
131
+ if images.max() > 1.0:
132
+ images = images * SCALE
133
 
134
+ # Example: predict the first sample in the npy file
135
+ sample = np.expand_dims(images[0], axis=0) # (1, H, W, 3)
136
+ prob = model.predict(sample, verbose=0)[0]
137
+ pred_idx = int(np.argmax(prob))
138
+ print(f"[Dataset sample 0] Predicted: {idx_to_class[pred_idx]} | confidence: {prob[pred_idx]:.4f}")