File size: 9,634 Bytes
12631d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
---
license: apache-2.0
tags:
- agriculture
- plant-pathology
- crop-disease
- computer-vision
- yolo26
- efficientnet
- soil-moisture
- bangladesh
- multimodal
datasets:
- agricultural-vision
metrics:
- accuracy
- rmse
library_name: ultralytics
pipeline_tag: image-classification
---

# KrishokChat: Agricultural Vision & Soil Intelligence Model Suite

This repository contains the complete, production-ready suite of machine learning models developed for the **KrishokChat Advisory System**. These models are packaged into self-contained, folderized directories to enable academic reviewers, agronomists, and developers to reproduce and run our full diagnostic pipeline locally without requiring expensive cloud GPU servers.

---

## 1. Architectural Overview

The KrishokChat perception and diagnostic stack uses a multi-tier decoupled architecture:
1. **Tier 1: Crop Species Identification** β€” A `YOLO26-cls` model identifying 10 major crop families in Bangladesh to eliminate cross-crop pesticide misbinding hazard.
2. **Tier 2: Specialized Crop Pathology Diagnosis** β€” Six per-crop dedicated `YOLO26-cls` models diagnosing foliar fungal, bacterial, viral, and physiological diseases.
3. **Tier 3: Soil Moisture Matric Tension Estimation** β€” A 5-fold cross-validated `EfficientNet-B0` regression model predicting continuous soil suction pressure ($\text{kPa}$) directly from field images for precision irrigation guidance.

```
                   [ Farmer Field Leaf Image ]
                               β”‚
                               β–Ό
                   [ 01_crop_classifier ] (YOLO26-cls)
             β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
             β”‚                 β”‚                 β”‚
             β–Ό                 β–Ό                 β–Ό
     [ 02_potato_disease ]  [ 03_rice_disease ]  [ 04_wheat_disease ] ...
             β”‚                 β”‚                 β”‚
             β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                               β–Ό
               [ Diagnosis + Bangla Treatment Advice ]
```

---

## 2. Model Catalog & Checkpoint Manifest

Every PyTorch weight (`.pt`) is named distinctively with zero ambiguity. Corresponding optimized `ONNX` weights are included for cross-platform edge deployment.

| # | Directory | PyTorch Weight (`.pt`) | Edge ONNX (`.onnx`) | Architecture | Classes / Output | Target Crop / Task |
|:---:|:---|:---|:---|:---:|:---:|:---|
| **1** | `01_crop_classifier` | `crop_classifier.pt` (10.5 MB) | `crop_classifier.onnx` (20.8 MB) | YOLO26-cls | 10 classes | Multi-crop species classification |
| **2** | `02_potato_disease` | `potato_disease.pt` (10.5 MB) | `potato_disease.onnx` (20.8 MB) | YOLO26-cls | 3 classes | Potato (*Solanum tuberosum*) |
| **3** | `03_rice_disease` | `rice_disease.pt` (19.9 MB) | `rice_disease.onnx` (39.6 MB) | YOLO26-cls | 10 classes | Rice (*Oryza sativa*) |
| **4** | `04_wheat_disease` | `wheat_disease.pt` (9.0 MB) | `wheat_disease.onnx` (5.9 MB) | YOLO26-cls | 11 classes | Wheat (*Triticum aestivum*) |
| **5** | `05_corn_disease` | `corn_disease.pt` (10.5 MB) | `corn_disease.onnx` (20.8 MB) | YOLO26-cls | 4 classes | Corn / Maize (*Zea mays*) |
| **6** | `06_chilli_disease` | `chilli_disease.pt` (3.1 MB) | `chilli_disease.onnx` (5.9 MB) | YOLO26-cls | 8 classes | Chilli (*Capsicum annuum*) |
| **7** | `07_brassica_disease` | `brassica_disease.pt` (10.5 MB) | `brassica_disease.onnx` (20.8 MB) | YOLO26-cls | 11 classes | Cabbage & Cauliflower (*Brassica spp.*) |
| **8** | `08_soil_moisture` | `effnetb0_fold[0-4].pt` (81 MB) | N/A (PyTorch state_dict) | EfficientNet-B0 | 1 continuous (kPa) | Soil matric tension estimation |

---

## 3. Directory Layout

```text
backend_models/
β”œβ”€β”€ README.md                           # Main Model Card & Reviewer Documentation
β”œβ”€β”€ requirements.txt                    # Minimal pip dependencies
β”œβ”€β”€ verify_all_models.py                # Single-click automated diagnostic verification suite
β”œβ”€β”€ run_inference.py                    # Multi-model CLI inference runner
β”œβ”€β”€ upload_to_huggingface.py            # Hugging Face Hub upload automation script
β”‚
β”œβ”€β”€ 01_crop_classifier/                 # Intake Crop Classifier (10 classes)
β”‚   β”œβ”€β”€ crop_classifier.pt
β”‚   β”œβ”€β”€ crop_classifier.onnx
β”‚   β”œβ”€β”€ class_names.json
β”‚   └── README.md
β”‚
β”œβ”€β”€ 02_potato_disease/                  # Potato Pathology (Early Blight, Late Blight, Healthy)
β”‚   β”œβ”€β”€ potato_disease.pt
β”‚   β”œβ”€β”€ potato_disease.onnx
β”‚   β”œβ”€β”€ class_names.json
β”‚   β”œβ”€β”€ disease_details.json
β”‚   └── README.md
β”‚
β”œβ”€β”€ 03_rice_disease/                    # Rice Pathology (Blast, BLB, Sheath Blight, etc.)
β”‚   β”œβ”€β”€ rice_disease.pt
β”‚   β”œβ”€β”€ rice_disease.onnx
β”‚   β”œβ”€β”€ class_names.json
β”‚   β”œβ”€β”€ disease_details.json
β”‚   └── README.md
β”‚
β”œβ”€β”€ 04_wheat_disease/                   # Wheat Pathology (Rusts, Blast, Tan Spot, etc.)
β”‚   β”œβ”€β”€ wheat_disease.pt
β”‚   β”œβ”€β”€ wheat_disease.onnx
β”‚   β”œβ”€β”€ class_names.json
β”‚   β”œβ”€β”€ disease_details.json
β”‚   β”œβ”€β”€ metadata.json
β”‚   └── README.md
β”‚
β”œβ”€β”€ 05_corn_disease/                    # Corn Pathology (Rust, Leaf Spot, Blight)
β”‚   β”œβ”€β”€ corn_disease.pt
β”‚   β”œβ”€β”€ corn_disease.onnx
β”‚   β”œβ”€β”€ class_names.json
β”‚   β”œβ”€β”€ disease_details.json
β”‚   └── README.md
β”‚
β”œβ”€β”€ 06_chilli_disease/                  # Chilli Pathology (Bacterial Spot, Curl Virus, etc.)
β”‚   β”œβ”€β”€ chilli_disease.pt
β”‚   β”œβ”€β”€ chilli_disease.onnx
β”‚   β”œβ”€β”€ class_names.json
β”‚   β”œβ”€β”€ disease_details.json
β”‚   └── README.md
β”‚
β”œβ”€β”€ 07_brassica_disease/                # Crucifers (Cabbage / Cauliflower diseases)
β”‚   β”œβ”€β”€ brassica_disease.pt
β”‚   β”œβ”€β”€ brassica_disease.onnx
β”‚   β”œβ”€β”€ class_names.json
β”‚   β”œβ”€β”€ disease_details.json
β”‚   └── README.md
β”‚
β”œβ”€β”€ 08_soil_moisture/                   # Soil Moisture Tensiometer Regression (5-fold ensemble)
β”‚   β”œβ”€β”€ effnetb0_fold0.pt ... fold4.pt
β”‚   β”œβ”€β”€ oof_predictions.csv
β”‚   β”œβ”€β”€ pred_vs_actual.png
β”‚   β”œβ”€β”€ model_def.py
β”‚   └── README.md
β”‚
└── sample_images/                      # Representative leaf images for zero-setup verification
    β”œβ”€β”€ crop_sample.jpg
    β”œβ”€β”€ potato_sample.jpg
    β”œβ”€β”€ rice_sample.jpg
    β”œβ”€β”€ wheat_sample.jpg
    β”œβ”€β”€ corn_sample.jpg
    β”œβ”€β”€ chilli_sample.jpg
    └── brassica_sample.jpg
```

---

## 4. Quickstart Guide for Academic Reviewers

### Step 1: Install Dependencies
```bash
cd backend_models
pip install -r requirements.txt
```

### Step 2: Automated Verification of All Models
Run the automated test runner to verify that every single model checkpoint loads into memory, performs forward inference, and verifies against class specifications:
```bash
python verify_all_models.py
```

### Step 3: Run Standalone Inferences

**Test Potato Disease Diagnosis:**
```bash
python run_inference.py --crop potato --image sample_images/potato_sample.jpg
```

**Test Rice Disease Diagnosis:**
```bash
python run_inference.py --crop rice --image sample_images/rice_sample.jpg
```

**Test Wheat Disease Diagnosis:**
```bash
python run_inference.py --crop wheat --image sample_images/wheat_sample.jpg
```

**Test Soil Moisture Regression:**
```bash
python run_inference.py --task soil --image sample_images/crop_sample.jpg
```

---

## 5. Python API Usage

### Vision Models (YOLO26)
```python
from ultralytics import YOLO

# Load any specialized YOLO26 pathology classifier
model = YOLO("02_potato_disease/potato_disease.pt")

# Predict on an RGB image
results = model.predict("sample_images/potato_sample.jpg", imgsz=224, verbose=False)[0]

top_class = model.names[results.probs.top1]
confidence = float(results.probs.top1conf)
print(f"Result: {top_class} ({confidence:.2%})")
```

### Soil Moisture Regression (5-Fold Ensemble)
```python
import sys
sys.path.insert(0, "08_soil_moisture")
from model_def import load_soil_model
import torch
import torchvision.transforms as T
from PIL import Image

transform = T.Compose([
    T.Resize((224, 224)),
    T.ToTensor(),
    T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])
])

img = transform(Image.open("sample_images/crop_sample.jpg").convert("RGB")).unsqueeze(0)

# Ensemble average across 5 folds
predictions = []
for fold in range(5):
    m = load_soil_model(f"08_soil_moisture/effnetb0_fold{fold}.pt")
    with torch.no_grad():
        predictions.append(m(img).item())

mean_kpa = sum(predictions) / len(predictions)
print(f"Estimated Soil Matric Potential: {mean_kpa:.2f} kPa")
```

---

## 6. Uploading to Hugging Face Hub

To publish this suite to the official Hugging Face repository:
```bash
python upload_to_huggingface.py --token <YOUR_HF_TOKEN>
```
Target repository: `https://huggingface.co/RaiyanKhaan/KrishokTech-Models`

---

## 7. Citation
If you use these model weights or the KrishokChat pipeline in your research, please cite our paper:

```bibtex
@inproceedings{krishokchat2026,
  title={KrishokChat: A Grounded Multi-Modal Agricultural Advisory and Pathology Diagnostic System for Smallholder Farming},
  author={Reza, Raiyaan and Khaan, Raiyan and Collaborators},
  booktitle={Proceedings of the European Chapter of the Association for Computational Linguistics (EACL)},
  year={2026}
}
```