An automated trash sorting system using YOLOv8 for waste classification. This project uses deep learning to classify different types of waste materials, helping to improve recycling efficiency.
The training script is optimized for different hardware configurations:
- Utilizes Metal Performance Shaders (MPS) for GPU acceleration
- Optimized for unified memory architecture
- For M4 Pro with 24GB RAM:
- Batch size: 24
- Worker threads: 6
- Mixed precision training enabled
- Image caching enabled
- Expected training time: 2-3 hours
- CUDA acceleration support
- For RTX 4070 Ti (12GB VRAM):
- Batch size: 32
- Worker threads: 8
- Mixed precision training enabled
- Expected training time: 1-2 hours
- Fallback option for systems without GPU
- Optimized parameters:
- Batch size: 8
- Worker threads: 4
- Expected training time: 15-20 hours
Uses the Garbage Classification dataset from Kaggle, which includes:
- 12 waste categories
- ~15,000 images
- Categories: battery, biological, brown-glass, cardboard, clothes, green-glass, metal, paper, plastic, shoes, trash, white-glass
pip install -r requirements.txtMain dependencies:
- Python 3.8+
- PyTorch
- Ultralytics YOLOv8
- Kaggle API
- OpenCV
- Install dependencies:
pip install -r requirements.txt- Set up Kaggle credentials:
- Go to your Kaggle account settings
- Click on 'Create New API Token'
- Save the kaggle.json file to ~/.kaggle/kaggle.json
- Set permissions:
chmod 600 ~/.kaggle/kaggle.json
Run the training script:
python train.pyThe script will:
- Download and prepare the dataset
- Automatically detect your hardware and optimize training parameters
- Train the YOLOv8 model
- Save the best model and training results
├── data/
│ ├── images/
│ │ ├── train/
│ │ ├── val/
│ │ └── test/
│ ├── labels/
│ │ ├── train/
│ │ ├── val/
│ │ └── test/
│ └── trashnet/
├── runs/
│ └── train/
├── train.py
├── requirements.txt
└── README.md
- Model: YOLOv8n (nano)
- Image size: 640x640
- Epochs: 50
- Optimizer: Adam
- Learning rate: 0.001
- Data augmentation:
- Horizontal flip
- Translation
- Scale
- Mosaic
Training results and model checkpoints are saved in the runs/train/trash_sorter directory, including:
- Best model weights
- Training metrics
- Confusion matrix
- PR curves
- Training plots
Minimum:
- 8GB RAM
- 10GB storage space
- CPU with 4+ cores
Recommended:
- Apple M-series chip with 16GB+ RAM or NVIDIA GPU with 8GB+ VRAM
- 20GB+ storage space
- SSD for faster data loading
This project is licensed under the MIT License - see the LICENSE file for details.
- Dataset: Garbage Classification on Kaggle
- YOLOv8: Ultralytics