--- title: Yoloapi emoji: 📉 colorFrom: indigo colorTo: blue sdk: docker pinned: false license: mit --- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference # 🌾 AgriVision: Precision Weed & Crop Detection System ![Python](https://img.shields.io/badge/Python-3.10-blue?style=for-the-badge&logo=python&logoColor=white) ![YOLOv8](https://img.shields.io/badge/Model-YOLOv8x-orange?style=for-the-badge) ![FastAPI](https://img.shields.io/badge/Backend-FastAPI-green?style=for-the-badge&logo=fastapi&logoColor=white) ![Docker](https://img.shields.io/badge/Deployment-Docker-blue?style=for-the-badge&logo=docker&logoColor=white) ![License](https://img.shields.io/badge/License-MIT-lightgrey?style=for-the-badge) > **AgriVision** is a high-performance computer vision system designed to automate the differentiation between crops and invasive weeds. It serves as the intelligent backend for autonomous agricultural robotics and drone surveillance, aiming to reduce herbicide usage by up to 90% through precision targeting. --- ## 📑 Table of Contents 1. [Project Overview](#-project-overview) 2. [System Architecture](#-system-architecture) 3. [Key Features](#-key-features) 4. [Tech Stack](#-tech-stack) 5. [Installation & Setup](#-installation--setup) 6. [API Documentation](#-api-documentation) 7. [Project Structure](#-project-structure) 8. [Developer's Note](#-developers-note) --- ## 🔭 Project Overview Modern agriculture faces a dual challenge: maximizing yield while minimizing environmental impact. Traditional "blanket spraying" of herbicides is inefficient and ecologically damaging. **AgriVision** addresses this by enabling **Site-Specific Weed Management (SSWM)**. By processing visual data in real-time, the system identifies the exact coordinates of weeds versus crops, allowing robotic actuators to target only the invasive plants. ### Impact Goals: * **🌱 Sustainability:** Drastic reduction in chemical runoff. * **💰 Economic Efficiency:** Lower input costs for farmers. * **⚡ Real-Time Processing:** Optimized for edge deployment (e.g., NVIDIA Jetson). --- ## 🏗 System Architecture The system is built on a **Microservice Architecture**, encapsulating the State-of-the-Art (SOTA) **YOLOv8** model within a scalable **FastAPI** container. ### High-Level Data Flow 1. **Input:** Edge devices (drones/cameras) send raw image frames via REST API. 2. **Preprocessing:** Images are resized (640px) and normalized. 3. **Inference:** The YOLOv8x model (loaded in memory) performs object detection. 4. **Post-Processing:** Bounding boxes are drawn, and JSON metadata is extracted. 5. **Response:** The client receives both the analytical data and the visualized result. ### 📐 Architecture Diagram ```mermaid graph TD subgraph "Client Layer" Drone[🚁 Agricultural Drone] App[📱 Mobile Dashboard] end subgraph "FastAPI Container" API[🚀 API Gateway] subgraph "Inference Engine" Pre[⚙️ Preprocessor] Model{🧠 YOLOv8 Model} Post[🎨 Annotator & JSON Builder] end end subgraph "Data & Weights" Weights[(📦 Model Weights .pt)] end Drone -->|POST /predict (Image)| API App -->|POST /predict (Image)| API API --> Pre Pre -->|Tensor| Model Weights -.->|Load on Startup| Model Model -->|Raw Detections| Post Post -->|JSON + Base64| API API -->|Response| Drone API -->|Response| App Key Features Real-Time Inference: Optimized pipeline ensures low latency responses (<200ms on GPU). Dual Output: Returns both structured data (JSON for robots) and visual overlays (Images for humans). Confidence Filtering: Configurable thresholds to minimize false positives. Containerized: Fully Dockerized for "Write Once, Run Anywhere" deployment. Scalable: Stateless design allows horizontal scaling using Kubernetes or Cloud Run. Component,Technology,Rationale Model,Ultralytics YOLOv8x,chosen for highest mAP (Mean Average Precision) over speed. Backend,FastAPI,"Asynchronous, strict typing (Pydantic), and auto-documentation." Image Proc,Pillow (PIL),Efficient image manipulation and format conversion. Container,Docker,Ensures consistent environment across dev and production. Server,Uvicorn,Lightning-fast ASGI server implementation. 📡 API Documentation POST /predict Upload an image to get detection results. Request: multipart/form-data file: The image file (JPEG/PNG) Response Example (JSON): JSON { "meta": { "count": 2, "model": "YOLOv8-X", "inference_time": "0.14s" }, "detections": [ { "class_id": 0, "label": "weed", "confidence": 0.94, "bbox": [120.5, 300.2, 180.1, 410.5] } ], "annotated_image_base64": "iVBORw0KGgoAAAANSUhEUgAA..." } 👨‍💻 Developer's Note To the Admissions Committee & Reviewers: This repository represents the final, consolidated production version (v2.1) of my work on agricultural computer vision. In the spirit of Clean Code and professional engineering practices, I have refactored the experimental notebooks into this deployable microservice. My development journey involved extensive experimentation with: Comparing YOLOv5 vs YOLOv8 architectures. Fine-tuning Non-Maximum Suppression (NMS) thresholds. Optimizing Docker image layers for faster cold starts. For access to the raw training logs, dataset preparation scripts, or previous experimental branches, please refer to my Archived Research Repository. or can see the outputs in kaggle notebooks "https://www.kaggle.com/code/omgwhatisthis/yolov8x-weed-crop-detection"