Agriculture_Decision_System

AgriVision Decision Support System

High-Precision Computer Vision for Agronomic Intelligence

Python PyTorch YOLOv8 Streamlit Hugging Face Google Colab OpenCV Git



πŸš€ Engineering Deployment & Live Documentation with Research Paper

Resource Description Action
Production Inference Engine Live YOLOv8 pipeline hosted on Hugging Face Space. Run Live Demo
Technical Architecture Interactive Reveal.js slide deck (Socratic Method). View Presentation
Research Foundations Full mathematical breakdown and ablation study (CVPR). Read Research Paper

πŸ“Έ Visual Preview

YOLOv8 wheat head detection with per-object confidence scores

Real-time wheat head detection with per-object confidence scoring β€” Tuned YOLOv8s at 1024px resolution

AgriVision analytics dashboard β€” yield estimation, spatial uniformity, revenue projection, and PDF report export

Automated agronomic analytics: Yield estimation (t/ha), Spatial Uniformity (CV%), Revenue projection, and one-click PDF Executive Briefing export


Executive Summary

The AgriVision Decision Support System represents an end-to-end Machine Learning pipeline engineered to supersede traditional, labor-intensive manual crop counting methodologies. By ingesting high-resolution drone imagery, the system leverages a custom-tuned YOLOv8 architecture to accurately detect and segment wheat heads across complex field topologies. This robust automated framework enables the reproducible extraction of highly localized visual features with a precision fundamentally unattainable through legacy human inspection.

Moving strictly beyond rudimentary object detection, the architecture acts as a deterministic conduit between pixel space and actionable business intelligence. Raw bounding box vectors are algorithmically fused with region-specific agronomic constantsβ€”including Thousand Grain Weight (TGW) and localized grain density metricsβ€”to instantly compute crucial agricultural indicators. This engine delivers rapid field yield estimations (t/ha), calculates spatial Coefficient of Variation (CV%) to highlight localized physiological stress, projects direct financial returns, and subsequently synthesizes these analytics into presentation-ready PDF briefings for farm management stakeholders.

System Architecture & Problem Domain

The Problem

Traditional agriculture continues to heavily rely on manual field scouting and crop counting, representing a significant friction point in modern farm operations. This legacy process is prohibitively slow, rendering it grossly unscalable across broadacre farming. Furthermore, localized manual sampling is statistically error-prone due to human fatigue and the complex, overlapping nature of dense wheat canopies. This critical lack of deterministic spatial data severely blindsides farm managers, ultimately making accurate macro-level yield forecasting and rapid localized stress detection nearly impossible prior to the physical harvest.

The Pipeline Architecture

To eliminate manual sampling bottlenecks, the AgriVision system establishes a highly optimized, fully automated data pipeline. The model’s baseline weights were meticulously trained on large-scale, domain-specific agricultural dataβ€”predominantly the multi-regional Global Wheat Datasetβ€”ensuring robustness against varying phenotypic traits and illumination states.

The analytical flow operates synchronously as follows:


πŸ—οΈ Project Structure

Agriculture_Decision_System/
β”œβ”€β”€ app.py                          # Streamlit application entry point
β”œβ”€β”€ style.css                       # Custom dark-theme UI stylesheet
β”œβ”€β”€ requirements.txt                # Pinned production dependencies
β”œβ”€β”€ requirements_cloud.txt          # Lightweight cloud deployment deps
β”‚
β”œβ”€β”€ src/                            # Core backend modules
β”‚   β”œβ”€β”€ config.py                   # Regional agronomic constants (10 regions)
β”‚   β”œβ”€β”€ analytics.py                # Yield estimation, CV%, revenue engine
β”‚   β”œβ”€β”€ inference.py                # YOLOv8 model loading & batch inference
β”‚   β”œβ”€β”€ report.py                   # Automated PDF report generation (FPDF)
β”‚   β”œβ”€β”€ model.py                    # Model wrapper utilities
β”‚   β”œβ”€β”€ metrics.py                  # Evaluation metric helpers
β”‚   β”œβ”€β”€ dataset.py                  # Dataset loading & preprocessing
β”‚   └── utils.py                    # Shared utility functions
β”‚
β”œβ”€β”€ scripts/                        # Training, evaluation & analysis tools (18 scripts)
β”‚   β”œβ”€β”€ train.py                    # Model training script
β”‚   β”œβ”€β”€ evaluate_model.py           # mAP / Precision / Recall evaluation
β”‚   β”œβ”€β”€ compare_models.py           # Baseline vs. Tuned comparison pipeline
β”‚   β”œβ”€β”€ extract_false_negatives.py  # FN forensic extraction
β”‚   β”œβ”€β”€ extract_false_positives.py  # FP forensic extraction
β”‚   β”œβ”€β”€ generate_pro_dashboard.py   # Advanced visualization dashboards
β”‚   └── ...                         # Additional diagnostic utilities
β”‚
β”œβ”€β”€ notebooks/                      # Jupyter research notebooks
β”‚   β”œβ”€β”€ 01_Basic_EDA.ipynb          # Exploratory Data Analysis
β”‚   β”œβ”€β”€ 02_yolov8s_baseline_train.ipynb
β”‚   └── 03_YOLOv8s_training_iteration2(tuned).ipynb
β”‚
β”œβ”€β”€ configs/                        # YAML training configurations
β”‚   β”œβ”€β”€ wheat_v8.yaml               # Dataset config
β”‚   β”œβ”€β”€ yolov8_baseline_args.yaml   # Baseline hyperparameters
β”‚   └── yolov8_tuned.yaml           # Tuned hyperparameters
β”‚
β”œβ”€β”€ docs/                           # Technical documentation & visual assets
β”‚   β”œβ”€β”€ error_analysis_report.md
β”‚   β”œβ”€β”€ hyperparameter_rationale.md
β”‚   β”œβ”€β”€ iteration_2_evaluation.md
β”‚   └── assets/                     # Analytical charts & dashboards
β”‚
β”œβ”€β”€ data/                           # Dataset directory (gitignored)
β”‚   β”œβ”€β”€ raw/                        # Original images & annotations
β”‚   β”œβ”€β”€ processed/                  # YOLO-formatted data
β”‚   └── test_samples/               # Quick-test imagery
β”‚
β”œβ”€β”€ tests/                          # Unit tests
β”‚   └── test_metrics.py
β”‚
β”œβ”€β”€ outputs/                        # Training outputs & weights (gitignored)
β”œβ”€β”€ AgriVision_Paper/               # CVPR-format research paper (LaTeX)
└── LICENSE                         # MIT License

Agronomic Analytics Engine

The true engineering value of the AgriVision framework lies in its deterministic state engine, which bridges the gap between deep learning outputs and real-world agricultural operations. Rather than simply returning raw visualization overlays, the backend securely intercepts Machine Learning bounding box tensors, aggregates detection density, and applies rigorous agronomic mathematics to translate pixel geometry into actionable farming metrics.

Metric Agronomic Calculation Engineering Impact
Spatial Uniformity (CV%) Calculates the statistical Coefficient of Variation across the target sampling tiles. Acts as a high-fidelity indicator for field health. A low CV% confirms absolute growth consistency, while a high CV% rapidly highlights localized physiological crop stress or mechanical seeding failures.
Estimated Yield (t/ha) Translates raw detection density into gross output using region-specific constants (e.g., Thousand Grain Weight). Converts abstract network counts into mathematically grounded tonnage per hectare, unlocking the ability to execute highly predictive macro-level harvest forecasting.
Projected Revenue Fuses the spatial Yield output with current localized commodity market pricing. Delivers hyper-localized financial modeling projections, rendering projected monetary returns in the selected regional currency to inform immediate strategic fiscal planning.

Automated Executive Reporting

Upon the termination of an inference run, the data payloads are algorithmically handed off to an automated document generation subsystem. To ensure absolute operational compatibility across volatile, read-only stateless cloud architectures, the system utilizes a highly optimized byte-stream encoder via the FPDF library (leveraging strictly dest='S'). This effectively packages all captured spatial metrics, network confidence outputs, and complex financial projections directly into memory as raw bytes. The Streamlit presentation layer then safely serves this dynamically generated PDF report, circumventing legacy server file-system restrictions to deliver a presentation-ready, zero-latency briefing directly to execution stakeholders.


πŸ“Š Model Performance & Validation

The tuned YOLOv8s model was rigorously validated against a 548-image holdout partition from the Global Wheat Head Detection dataset. Complete methodology, mathematical proofs, and ablation results are documented in the research paper.

Head-to-Head: Baseline vs. Tuned Model

Metric Baseline (640px) Tuned (1024px) Ξ”
mAP@50 0.950 0.944 βˆ’0.006
mAP@50-95 0.569 0.563 βˆ’0.006
Precision 0.877 0.873 βˆ’0.004
Recall 0.974 0.906 βˆ’0.068
Median Confidence 0.434 0.605 +39.4%
Training Epochs 50 (full run) 35 (early stop) βˆ’30%

Key Insight: The tuned model trades marginal recall (βˆ’6.8%) for a +39.4% increase in prediction confidence, eliminating 1,092 zero-IoU hallucinated detections that would have inflated yield estimates by 4–8%. In precision agriculture, fewer confident predictions are operationally superior to many uncertain ones.

Confidence Density & Aggregate Performance

Baseline vs Tuned model comparison β€” confidence density, hallucination reduction, and aggregate metrics

Left: Hallucination cull (violin). Center: Confidence density shift from 0.434 β†’ 0.605. Right: Aggregate precision/recall/F1 comparison.

Baseline Error Forensics

Baseline YOLOv8s false negative diagnostic β€” scale degradation and photometric fragility analysis

Systematic decomposition of baseline failure modes: scale degradation on micro-objects (top-left), photometric fragility in low-light zones (top-right), the critical "danger zone" of small + dark targets (bottom-left), and aspect ratio deformation (bottom-right).

Tuned Model Error Distribution

Tuned model error forensics β€” FP/FN distribution, crowd-scene immunity, and Jaccard index analysis

Tuned model forensics: FP/FN distribution (top-left), crowd-scene immunity with near-flat FN trend slope of 0.033 (top-right), clean vs. hallucinating confidence (bottom-left), and persistent Jaccard Index > 0.50 even under critical FP stress (bottom-right).


Developer Guide: Local Deployment

To replicate this environment locally for development or auditing purposes, follow the strict initialization sequence below. Ensure you are running Python 3.11+ before beginning.

1. Repository Cloning

Establish your local workspace by cloning the source repository from GitHub and navigating into the root directory:

git clone https://github.com/VaheGdlyan/Agriculture_Decision_System.git
cd Agriculture_Decision_System

2. Environment Setup

Isolate the deployment environment by initializing a custom Python virtual environment named venv311.

For Windows (PowerShell):

python -m venv venv311
.\venv311\Scripts\Activate.ps1

For Windows (CMD):

python -m venv venv311
venv311\Scripts\activate.bat

For Linux / macOS Systems:

python3 -m venv venv311
source venv311/bin/activate

3. Dependency Installation

Install all project dependencies:

pip install -r requirements.txt

4. System Initialization

Launch the application on localhost:

streamlit run app.py

System Limitations & Future Roadmap

To maintain engineering transparency, the following technical boundaries of the current iteration are strictly documented alongside our strategic scaling roadmap.

Current Limitations

Strategic Roadmap

The next technical iterations of the AgriVision framework are prioritized as follows:

  1. Multi-Spectral Integration: Transitioning beyond standard RGB matrices to natively ingest multi-spectral optical data (e.g., NDVI indices), enabling profound biological health analyses and direct correlation with chlorophyll density.
  2. Phenotypic State Classification: Expanding the core training dataset to facilitate multi-class bounding box differentiation, targeting the automated localization of critical crop disease states (e.g., early-stage wheat rust detection).
  3. Microservices Detachment (REST API): Developing a high-concurrency API endpoint utilizing FastAPI to cleanly decouple the heavy inference engine from the Streamlit frontend, streamlining direct integration with third-party mobile applications and IoT arrays.

πŸ“„ Citation

If you use this work in your research, please cite:

@misc{gdlyan2026agrivision,
  title        = {AgriVision: Error-Driven Hyperparameter Optimization for 
                  High-Confidence Wheat Head Detection in UAV Imagery},
  author       = {Gdlyan, Vahe},
  year         = {2026},
  howpublished = {\url{https://github.com/VaheGdlyan/Agriculture_Decision_System}},
  note         = {CVPR format}
}

πŸ§‘β€πŸ’» Author

Vahe Gdlyan

GitHub LinkedIn Medium


License

This project is open-source and released under the MIT License.