Fertilizer Classification
Using YOLOv8 and DeepSort to classify different types of fertilizers based on images, enabling automated quality control and inventory management.

Timeline
Started
November 2023 –
Completed
December 2023
Duration
1 months
Technologies
- Python 3.8
- YOLOv8
- DeepSort
- PyTorch
- OpenCV
Data Sources
- Phan Bon Ca Mau Dataset
- Custom collected images
- Augmented synthetic data
Project Overview
The Fertilizer Classification project was developed as part of my participation in IIoT Automation Solutions 2023. The goal of the project is to create an automated system for identifying and classifying different types of fertilizers based on their visual characteristics.
This system employs state-of-the-art computer vision techniques to support quality control, inventory management, and counterfeit detection in the agricultural supply chain.
By leveraging YOLOv8 for object detection and DeepSort for object tracking, the system can process images of fertilizer products and accurately classify them into predefined categories—even under challenging conditions such as varying lighting, partial occlusion, or different packaging orientations.
Key Features
- Real-time fertilizer detection and classifica
- Robust performance across different lighting conditions
- Integration with inventory management systems
Methodology
The project followed a structured approach:
- Data collection from Phan Bon Ca Mau and custom sources
- Data preprocessing and augmentation
- YOLOv8 model training for fertilizer detection
- DeepSort implementation for consistent tracking
- Model optimization for edge devices
- Integration with user interface
Results & Impact
Model Performance
- Accuracy: 95.7%
- Precision: 0.943
- Recall: 0.962
- F1 Score: 0.952
The model achieved excellent performance across all fertilizer types, with particularly strong results for NPK and organic fertilizers. The system can process approximately 3 images per second on standard hardware, making it suitable for real-time applications.
Implementation at Phan Bon Ca Mau resulted in significant improvements in quality control processes, reducing manual inspection time by over 65% and decreasing classification errors by 87%. The system has been successfully deployed in both factory and warehouse environments.
Technical Architecture
# YOLOv8 Model Configuration
model = YOLO('yolov8n.pt')
model.train(
data='fertilizer_dataset.yaml',
epochs=100,
imgsz=640,
batch=16,
name='fertilizer_model',
patience=20,
device=0
)
# DeepSort Configuration
deepsort = DeepSort(
model_path='osnet_x0_25_market1501.pt',
max_dist=0.2,
min_confidence=0.3,
max_iou_distance=0.7,
max_age=70,
n_init=3,
nn_budget=100
)
Data Pipeline
The data pipeline was designed to handle diverse image inputs and ensure model robustness:
- Multi-source image collection
- Automated data augmentation (rotation, flipping, color shifts)
- Annotation using a custom labeling tool
- Train/validation/test split (70/15/15)
Deployment
The system was deployed using:
- QT5 framework for desktop deployment
Challenges & Solutions
Limited Training Data
Challenge: The initial dataset contained only 500 images across 8 fertilizer types.
Solution: Implemented extensive data augmentation techniques and synthetic data generation to expand the dataset to over 5,000 images. Used transfer learning from pre-trained models to improve performance with limited data.
Variable Lighting Conditions
Challenge: Field conditions have highly variable lighting, affecting model performance.
Solution: Trained the model with images captured under different lighting conditions and applied adaptive histogram equalization as a preprocessing step to normalize lighting variations.
Edge Deployment
Challenge: Deploying a computationally intensive model on resource-constrained devices.
Solution: Applied model quantization and pruning to reduce model .
Future Improvements
While the current system performs well, several enhancements are planned for future iterations:
- Integration of NIR (Near-Infrared) imaging for content verification
- Expansion to include more fertilizer types and brands
- Development of a mobile app for farmers to verify authenticity
- Implementation of a blockchain-based verification system
- Automated nutrient content estimation from packaging information
These improvements aim to create a comprehensive solution for fertilizer quality control and authentication throughout the agricultural supply chain, benefiting both manufacturers and farmers.