Overview
Reciclaje AI uses YOLOv8 (You Only Look Once version 8), a state-of-the-art real-time object detection model from Ultralytics. YOLOv8 combines speed and accuracy, making it ideal for real-time waste classification applications.Why YOLOv8?
Real-Time Performance
YOLOv8 processes frames in milliseconds, enabling smooth real-time video analysis without lag.
High Accuracy
Advanced architecture provides precise bounding boxes and confident classifications.
Easy Integration
Ultralytics library offers simple Python API for model loading and inference.
Efficient Training
Can be trained on custom datasets with relatively small amounts of labeled data.
Model Integration
The YOLOv8 model is integrated into Reciclaje AI using the Ultralytics library:The
best.pt file contains the trained model weights. This file is generated during the training process and contains learned patterns for detecting the 5 waste categories.Model Architecture Components
YOLOv8 consists of three main components:Backbone
CSPDarknet extracts features from input images using convolutional layers. It identifies low-level features (edges, textures) and high-level features (object shapes, patterns).
- Processes 640×640 pixel input images (default)
- Uses efficient cross-stage partial connections
- Reduces computational cost while maintaining accuracy
Neck
Path Aggregation Network (PANet) combines features from different scales to detect objects of various sizes.
- Merges features from multiple layers
- Enables detection of both small and large waste items
- Improves localization accuracy for bounding boxes
Inference Process
When a frame is passed to the model, YOLOv8 follows this process:Key Inference Parameters
stream=True
stream=True
Enables memory-efficient inference for video streams. The model yields results as they’re produced instead of storing all detections in memory.Essential for real-time applications where frames are processed continuously.
verbose=False
verbose=False
Suppresses detailed logging output during inference. Improves performance by reducing I/O operations.Set to
True during debugging to see detailed model information.Image Size
Image Size
YOLOv8 typically resizes images to 640×640 for processing. The camera captures at 1280×720, which is automatically handled by the model.You can adjust input size during training for different speed/accuracy tradeoffs.
Detection Output Structure
YOLOv8 returns structured detection results:The
xyxy format represents bounding boxes as [x1, y1, x2, y2] where (x1, y1) is the top-left corner and (x2, y2) is the bottom-right corner.Model Training Overview
While the provided code uses a pre-trained model (best.pt), here’s how YOLOv8 models are trained:
Dataset Preparation
Collect and label images of waste materials:
- Capture diverse images of Metal, Glass, Plastic, Carton, and Medical waste
- Annotate bounding boxes and class labels
- Split into training, validation, and test sets
Model Variants
YOLOv8 comes in different sizes for various hardware capabilities:| Model | Size | Speed | Accuracy | Use Case |
|---|---|---|---|---|
| YOLOv8n | Nano | Fastest | Good | Mobile devices, edge computing |
| YOLOv8s | Small | Very Fast | Better | Embedded systems, Raspberry Pi |
| YOLOv8m | Medium | Fast | High | Standard laptops, GPUs |
| YOLOv8l | Large | Moderate | Very High | High-end workstations |
| YOLOv8x | XLarge | Slower | Highest | Maximum accuracy scenarios |
Performance Optimization
GPU Acceleration
YOLOv8 automatically uses CUDA-enabled GPUs when available, significantly improving inference speed.
Half Precision
Use FP16 inference for 2x speed improvement on compatible GPUs:
Batch Processing
Process multiple frames in batches for better GPU utilization:
Model Export
Export to optimized formats like ONNX or TensorRT:
Confidence Scoring
The model outputs a confidence score for each detection:The code uses
math.ceil() which rounds up the confidence. In production, you may want to preserve decimal precision or set a higher threshold (e.g., conf > 0.5) to filter low-confidence detections.Model Files Structure
.pt file is a PyTorch checkpoint containing:
- Neural network architecture definition
- Trained weight parameters
- Optimization state
- Model metadata (class names, input size, etc.)
Advantages for Educational Use
Visual Learning
Real-time bounding boxes and labels help students understand how AI “sees” objects.
Immediate Feedback
Fast inference provides instant results, keeping students engaged.
Practical Application
Demonstrates computer vision concepts with a meaningful environmental application.
Extensible Platform
Students can experiment with model parameters, add new classes, or adjust confidence thresholds.
Common Questions
Why not other object detection models?
Why not other object detection models?
YOLOv8 offers the best balance of speed and accuracy for real-time applications. Alternatives like Faster R-CNN are more accurate but too slow for real-time video. YOLOv8 achieves competitive accuracy while processing 30+ frames per second.
Can the model run without a GPU?
Can the model run without a GPU?
Yes, YOLOv8 can run on CPU, though at reduced speed. The nano (n) and small (s) variants are optimized for CPU inference. Expect 5-15 FPS on modern CPUs compared to 30-60+ FPS on GPUs.
How was best.pt created?
How was best.pt created?
The
best.pt file was created by training YOLOv8 on a custom dataset of labeled waste images. The training process involved:- Collecting diverse waste images
- Annotating objects with bounding boxes and class labels
- Training for multiple epochs
- Selecting the checkpoint with the best validation performance
Can I retrain the model?
Can I retrain the model?
Absolutely! You can fine-tune the existing model or train from scratch with additional data. This is useful for:
- Improving accuracy on specific waste types
- Adding new waste categories
- Adapting to different environmental conditions
- Specializing for regional recycling requirements
Next Steps
How It Works
See how YOLOv8 integrates into the detection pipeline
Detection Classes
Learn about the 5 waste categories the model detects
Additional Resources
Ultralytics YOLOv8 Documentation
Official documentation for YOLOv8, including training guides, API reference, and advanced configurations.