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: YOLOv8 (via SuperGradients)
- Framework: SuperGradients Training Library
- Backend: PyTorch
- Data Format: YOLO annotation style (bounding boxes + labels)
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
-
Environment Setup
- Uses Kaggle environment with common libraries pre-installed
- Installs
super-gradients
library for training
-
Dataset Preparation
- Loads the YOLO-formatted dataset and organizes it into
train
,val
, andtest
sets - Sets dataset paths and class names
- Loads the YOLO-formatted dataset and organizes it into
-
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)
- Loads the
-
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
-
-
Evaluation & Visualization
- Evaluates the best saved model on the test set
- Visualizes ground truth and prediction overlaps
- mAP@0.5: Measures precision across object confidence thresholds
- mAP@0.5:0.95: A more rigorous evaluation averaging over multiple IoU thresholds
The notebook includes visualization examples for:
- Ground truth bounding boxes
- Predicted detections after training
- Model performance comparison
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.
- Python β₯ 3.8
- torch
- numpy
- pandas
- matplotlib
- opencv-python
- super-gradients
- tqdm
.
βββ weed-detection-using-yolo-v8.ipynb
βββ README.md
βββ data-set.zip/
βββ Weed Detection/
This project notebook was created by samrocks03. If you find this helpful, feel free to star π the repo and share feedback!
This project is open-sourced under the MIT License.
- π Kaggle Notebook: Weed Detection using YOLOv8
- π Kaggle Dataset: Weed Detection Dataset