This project is a Recycling Detector that uses YOLOv8 to detect and classify different types of materials used in recyclable and non-recyclable items. The model is trained to identify seven different material types: cardboard, glass, materials, metal, paper, plastic, and trash.
The dataset is divided into training, validation, and testing sets:
- Training Images:
../train/images - Validation Images:
../valid/images - Testing Images:
../test/images
The model is trained on the following seven classes:
cardboardglassmaterialsmetalpaperplastictrash
The dataset for training and evaluation is sourced from Roboflow's Recyclables and Garbage Detection project.
- Roboflow Workspace: recycling-detector
- Project: Recyclables and Garbage Detection
- Version: 4
- License: MIT
- Dataset URL: Link to Dataset
To run the recycling detector, you will need the following:
- Python 3.8+
- YOLOv8 (from
ultralytics) - OpenCV for video capturing and image processing
-
Clone the repository:
git clone https://github.com/your-repo/recycling-detector.git
-
Install the required dependencies:
pip install ultralytics opencv-python
-
Download the dataset from Roboflow and place the images in their respective folders (
../train/images,../valid/images, and../test/images).
To train the YOLOv8 model, use the following command:
from ultralytics import YOLO
# Load your custom YOLOv8 model configuration
model = YOLO("yolov8n.yaml")
# Train the model
model.train(data="path/to/your/data.yaml", epochs=100)Make sure to update the data.yaml file with the correct paths to the dataset.
Once the model is trained, you can use it for real-time material detection through your webcam or on a set of images.
Here’s a sample code to run the detector on a webcam:
import cv2
from ultralytics import YOLO
# Load the trained YOLOv8 model
model = YOLO("./runs/detect/exp/weights/best.pt") # Replace with your trained model path
# Open the webcam
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
if not ret:
break
# Run inference
results = model.predict(source=frame)
# Annotate the frame with bounding boxes
annotated_frame = results[0].plot()
# Display the annotated frame
cv2.imshow('Recycling Detector', annotated_frame)
# Break on 'q' key press
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# Release the webcam and close the window
cap.release()
cv2.destroyAllWindows()To test the model on the test dataset, use the following command:
# Load the trained model and run it on the test set
results = model.val(data="path/to/your/data.yaml")After training, the model will output metrics such as mAP (mean Average Precision) to evaluate its performance on the test data. The predictions will include bounding boxes around detected materials along with the confidence score for each classification.
This project is licensed under the MIT License. See the LICENSE file for details.
- The dataset is sourced from Roboflow's Recyclables and Garbage Detection project.
- YOLOv8 by Ultralytics.
Feel free to modify and adapt this project to suit your needs!