Skip to content

samrocks03/weed-detection-using-yolo-v8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Weed Detection using YOLOv8

This repository contains a Jupyter Notebook demonstrating the use of the YOLOv8 object detection model to identify and classify weed and crop instances from agricultural field images. The goal is to leverage deep learning for precision agriculture by automating weed detection, which can lead to more targeted herbicide use and improved crop yields.

🧠 Model & Framework

  • Model: YOLOv8 (via SuperGradients)
  • Framework: SuperGradients Training Library
  • Backend: PyTorch
  • Data Format: YOLO annotation style (bounding boxes + labels)

πŸ“ Dataset

The notebook utilizes a weed detection dataset, which should be placed in the dataset/ directory at the project root, with the following structure:

Weed Detection/
β”œβ”€β”€ images/
β”‚   β”œβ”€β”€ train/
β”‚   β”œβ”€β”€ val/
β”‚   └── test/
β”œβ”€β”€ labels/
β”‚   β”œβ”€β”€ train/
β”‚   β”œβ”€β”€ val/
β”‚   └── test/

Each image has a corresponding YOLO-formatted label file. The dataset consists of two classes:

  • crop
  • weed

πŸ”§ Project Workflow

  1. Environment Setup

    • Uses Kaggle environment with common libraries pre-installed
    • Installs super-gradients library for training
  2. Dataset Preparation

    • Loads the YOLO-formatted dataset and organizes it into train, val, and test sets
    • Sets dataset paths and class names
  3. Model Definition

    • Loads the YOLOv8 and YOLO-NAS model from SuperGradients
    • Applies YOLO-specific loss and evaluation metrics (e.g., mAP@0.5, mAP@0.5:0.95)
  4. Training Configuration

    • Defines the following training parameters:

      • Epochs: 100
      • Batch size: 16
      • Optimizer: Adam with weight decay
      • Learning rate: 5e-4 with cosine decay
      • Mixed precision training: Enabled
      • EMA (Exponential Moving Average): Enabled
    • Trains the model using SuperGradients' Trainer module

  5. Evaluation & Visualization

    • Evaluates the best saved model on the test set
    • Visualizes ground truth and prediction overlaps

πŸ“Š Evaluation Metrics

  • mAP@0.5: Measures precision across object confidence thresholds
  • mAP@0.5:0.95: A more rigorous evaluation averaging over multiple IoU thresholds

πŸ–ΌοΈ Visualizations

The notebook includes visualization examples for:

  • Ground truth bounding boxes
  • Predicted detections after training
  • Model performance comparison

πŸš€ How to Run

You can run the notebook on Kaggle Notebooks or in a local Jupyter environment with GPU support. Ensure you have the following installed:

pip install super-gradients

Make sure to place the dataset in the expected directory structure before running the notebook.

πŸ“Œ Dependencies

  • Python β‰₯ 3.8
  • torch
  • numpy
  • pandas
  • matplotlib
  • opencv-python
  • super-gradients
  • tqdm

πŸ“‚ File Structure

.
β”œβ”€β”€ weed-detection-using-yolo-v8.ipynb
β”œβ”€β”€ README.md
└── data-set.zip/
    └── Weed Detection/

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

This project notebook was created by samrocks03. If you find this helpful, feel free to star 🌟 the repo and share feedback!


πŸ“„ License

This project is open-sourced under the MIT License.

πŸ”— Actual Implementation is on Kaggle:

Releases

No releases published

Packages

No packages published