nextgenyeild-api / docs /PROJECT_TRACKER.md
Hassan132's picture
Deploy NextGenYeild API to Hugging Face Spaces
c54c1bf
|
Raw History Blame Contribute Delete
8.48 kB
# NextGenYeild β€” Master Project Progress & Task Tracker
> **Project Name:** NextGenYeild: Crop & AI detector
> **Core Direction:** AI-based wheat growth-stage detection + temporal crop monitoring + decision support
> **Target Environment:** Farmer companion & decision-support mobile application
> **Last Updated:** November 4, 2026
---
## 1. System & Environment Specifications
| Component | Status | Details |
| :--- | :---: | :--- |
| **Operating System** | βœ… Verified | Windows 11 + WSL2 Ubuntu Linux |
| **GPU Hardware** | βœ… Verified | NVIDIA GeForce RTX 5070 (12 GB VRAM, Blackwell `sm_120`) |
| **Conda Environment** | βœ… Active | `FoMo4Wheat` (Python 3.11.16) |
| **PyTorch & CUDA** | βœ… Verified | `PyTorch 2.11.0+cu128` (Hardware accelerated on `sm_120`) |
| **Attention Kernel** | βœ… Verified | `xFormers 0.0.35` (Memory-efficient attention active) |
| **Model Weights** | βœ… Verified | `weight/FoMo4Wheat_base.pth` (86.6M params, ViT-B/14, SwiGLU, 4 chunks, 4 register tokens) |
| **Trained Head** | βœ… Verified | `weight/nextgenyeild_wgsp_head_v1.pth` (**99.06% Test Accuracy**, **0.9905 Macro F1**) |
| **Internal Imports** | βœ… Fixed | Symlink `dinov2 -> FoMo4Wheat` created to resolve package imports |
---
## 2. Master 15-Phase Roadmap & Status Tracker
| Phase # | Phase Title | Status | Completion Date | Key Output / Artifact |
| :---: | :--- | :---: | :---: | :--- |
| **1** | **Understand Existing FoMo4Wheat Repo** | **DONE** | 2026-09-28 | Documented architecture, hub code, and eval protocols. |
| **2** | **Verify Pretrained Model on Hardware** | **DONE** | 2026-09-28 | [`experiments/fomo4wheat_verify.py`](file:///home/shawaiz/fyp/FoMo4Wheat/experiments/fomo4wheat_verify.py) verified on RTX 5070. |
| **3** | **Understand Growth-Stage Task (WGSP)** | **DONE** | 2026-09-28 | Determined backbone is frozen; 6-class linear probe required. |
| **4** | **Create Local Dataset Structure** | **DONE** | 2026-09-28 | Created `data/` layout, [`.gitignore`](file:///home/shawaiz/fyp/FoMo4Wheat/data/.gitignore), and [`data/README.md`](file:///home/shawaiz/fyp/FoMo4Wheat/data/README.md). |
| **5** | **Build Real Experiment Pipeline** | **DONE** | 2026-10-18 | Re-extracted 1536-D features with matching SwiGLU backbone; trained linear head (`weight/nextgenyeild_wgsp_head_v1.pth`). Test Acc: **99.06%**, Macro F1: **0.9905**. |
| **6** | **Test on Realistic Images** | **DONE** | 2026-11-04 | Evaluated on 9,978 smartphone images (66.74% Acc, 0.6377 Macro F1) and 318 Pakistani field images (`data/external/phase6_evaluation_results.json`). Logged in Experiment #004. |
| **7** | **Determine Fine-Tuning Need** | ⏳ **NEXT** | *Pending* | Address the 32.3% handheld perspective domain gap via parameter-efficient fine-tuning (LoRA / adapted linear head) on mobile perspectives. |
| **8** | **Temporal Growth Monitoring** | ⏸️ Queued | *Pending* | Observation data model, timeline tracking, stage transitions. |
| **9** | **Decision Support Engine** | **DONE** | 2026-10-18 | Deterministic agronomic management rules matrix implemented in [`api/rules.py`](file:///home/shawaiz/fyp/FoMo4Wheat/api/rules.py) (irrigation, fertilizer, risks, pesticides). |
| **10** | **Backend / API Service** | **DONE** | 2026-10-18 | Production FastAPI server in [`api/server.py`](file:///home/shawaiz/fyp/FoMo4Wheat/api/server.py) with `/health`, `/stages`, `/predict` endpoints and CORS support. |
| **11** | **Model Versioning** | **DONE** | 2026-10-18 | Standardized checkpoint metadata schema and version tracking (`fomo4wheat-wgsp-v1`). |
| **12** | **NextGenYeild Mobile App** | ⏸️ Queued | *Pending* | Flutter/React Native farmer companion UI with uncertainty handling. |
| **13** | **Scope Management (No Overbuilding)** | ⏸️ Queued | *Ongoing* | Keep focus on Image β†’ Stage β†’ Timeline β†’ Decision Support. |
| **14** | **Comprehensive Documentation** | **DONE** | 2026-10-18 | [`docs/PROJECT_TRACKER.md`](file:///home/shawaiz/fyp/FoMo4Wheat/docs/PROJECT_TRACKER.md), [`docs/EXPERIMENT_LOG.md`](file:///home/shawaiz/fyp/FoMo4Wheat/docs/EXPERIMENT_LOG.md), and [`docs/MOBILE_API_INTEGRATION_GUIDE.md`](file:///home/shawaiz/fyp/FoMo4Wheat/docs/MOBILE_API_INTEGRATION_GUIDE.md). |
| **15** | **Final System Integration** | ⏸️ Queued | *Pending* | End-to-end integration: Mobile App ↔ Backend ↔ AI Pipeline. |
---
## 3. Key Findings & Technical Architecture (Phases 1–3)
### A. Nature of `FoMo4Wheat_base.pth`
* Trained via self-supervised DINOv2 on 2.5 million wheat canopy images (*ImAg4Wheat*).
* It is a **feature extractor**, not a ready-made 6-class classifier.
* It accepts RGB images ($518 \times 518$ or $224 \times 224$) and produces a **768-D representation** (CLS token) + spatial patch tokens ($1369 \times 768$-D).
### B. Downstream Classification Strategy
* **Freeze Backbone:** All 86.6M parameters of `FoMo4Wheat_base.pth` remain frozen (`requires_grad = False`).
* **Linear Probe Head:** A single linear layer mapping pooled representations (1536-D or 768-D) $\to 6$ classes:
$$\text{logits} = W \cdot \mathbf{x} + b \quad \text{where } W \in \mathbb{R}^{6 \times 1536}$$
* **Why this is optimal:**
1. Prevents catastrophic forgetting of the 2.5M-image pre-training.
2. Requires very little training time ($\approx 2\text{ minutes}$ on RTX 5070).
3. Uses $< 2\text{ GB}$ VRAM, running safely on your 12 GB card.
### C. The 6-Class Label Taxonomy
1. `0_tillering`
2. `1_jointing`
3. `2_booting`
4. `3_anthesis`
5. `4_grain_filling`
6. `5_maturity`
---
## 4. Current Dataset Layout (Phase 4)
```
data/
β”œβ”€β”€ README.md # Complete documentation of taxonomy & collection criteria
β”œβ”€β”€ .gitignore # Excludes image binaries from Git
β”œβ”€β”€ raw/ # Original uncurated datasets
β”œβ”€β”€ processed/ # Cleaned & normalized images
β”œβ”€β”€ train/ # 70% of data (6 stage subfolders)
β”œβ”€β”€ validation/ # 15% of data (6 stage subfolders)
β”œβ”€β”€ test/ # 15% held-out test data (6 stage subfolders)
└── external/ # Local smartphone / Pakistani field images
```
---
## 5. Completed Phase 6 Summary & Next Steps (Phase 7: Fine-Tuning Decision)
### A. Phase 6 Benchmark Outcomes (Experiment #004):
1. **WGSP-Smartphone-Data (9,978 Images across 6 Stages):**
* **Top-1 Accuracy:** **66.74%** (Macro F1: **0.6377**, Weighted F1: **0.6377**).
* **Inference Speed:** **8.1 ms / image** on RTX 5070 in fp16.
* **Late Reproductive Stability:** `4_grain_filling` achieves **0.8179 F1** (99.5% recall) and `5_maturity` achieves **0.8706 F1** (99.4% precision).
* **Handheld Angle Domain Shift:** `0_tillering` suffered a major recall drop (12.87%), with 75.9% of samples classified as `1_jointing`. When photographed at oblique handheld angles and close distances, leafy tillers mimic elongated jointing stems.
* **Strict Biological Contiguity:** Errors remain 100% adjacent to the true stage (zero tillering crops confused with mature crops).
2. **Pakistani Field Wheat & Weed Diagnostics (Kaggle Peshawar Dataset):**
* **Pakistani Field Wheat (159 Images):** **95.6%** accurately classified into early vegetative stages (`1_jointing` 81.8%, `0_tillering` 13.8%) with **85.23%** mean confidence, demonstrating strong feature transfer to local soil conditions.
* **Weed Interference Diagnostic (159 Images):** Out-of-distribution weeds reduce confidence to 80.17% (20.1% low-confidence samples) and cause false reproductive predictions (`booting` 8.2%, `maturity` 6.9%), scientifically validating the need for the **Image Quality & Canopy Gatekeeper (Phase 11)**.
### B. Phase 7 Action Plan (Determine Fine-Tuning Need):
1. **Target:** Bridge the 32.3% performance gap on handheld mobile imagery to reach > 85% smartphone accuracy.
2. **Investigation Paths:**
* **Option A (Lightweight):** Train an adapted linear probe head or MLP projection on pooled representations of the smartphone dataset (or combined CN + Smartphone data).
* **Option B (Parameter-Efficient PEFT / LoRA):** Apply Low-Rank Adaptation (LoRA) to the query/value projections of the frozen ViT-B/14 backbone while preserving base representations.
* **Option C (Guardrail Enforced):** Enforce strict IMU tilt guidance in the mobile app HUD (rejecting photos outside $45^\circ - 85^\circ$) to eliminate the shallow-angle tiller/jointing ambiguity at capture time.