Welcome to the YOLOv8 Object Detection Project! This repository encompasses the complete workflow of training, exporting, optimizing, and deploying a YOLOv8 model for efficient object detection. Whether you're a beginner or an experienced practitioner, this guide will help you navigate through each step seamlessly.
This project leverages the YOLOv8 architecture to perform object detection tasks. The workflow includes:
- Data Preparation: Handling various image formats, including HEIC.
- Model Training: Fine-tuning the YOLOv8 model on custom datasets.
- Model Exporting: Converting the trained model to ONNX format for enhanced interoperability.
- Inference: Running efficient object detection using ONNX Runtime.
- Optimization: Reducing model size and improving performance through simplification and quantization.
- Documentation: Ultralytics YOLOv8 Docs
YOLOv8_Object_Detection_Project/
βββ data/
β βββ object_detection_yolov8/
β βββ data.yaml
βββ Real_photos/
β βββ IMG_3766.HEIC
βββ trained_models/
β βββ yolov8_large_model.onnx
βββ runs/
β βββ detect/
β βββββ train5/
β βββ weights/
β βββ best.pt
βββ trained_models/
β βββ best.onnx
| βββ yolo_best.pt
βββ app/
β βββ main.py
βββ README.md
βββ requirements.txt
For this project, we utilized a combination of synthetic data and real-world photographs to train and evaluate our YOLOv8 object detection model. The synthetic data comprised high-resolution screenshots of objects captured from various angles, ensuring a diverse representation of each class. To streamline the annotation process and enhance data quality, we uploaded the dataset to Roboflow Dataset, a powerful platform for managing and augmenting computer vision datasets.
Within Roboflow, we meticulously annotated each image with precise bounding boxes around the objects of interest, ensuring consistency and accuracy across the dataset. To further improve the model's ability to generalize to real-world scenarios, we applied a series of advanced augmentation techniques available in Roboflow's augmentation pipeline. These augmentations included:
- Rotation: Randomly rotating images to simulate different object orientations and viewpoints.
- Scaling: Varying the size of objects within images to mimic different distances and sizes encountered in real-world environments.
- Brightness and Contrast Adjustment: Altering the lighting conditions to account for varying illumination in different settings.
- Flipping: Horizontally and vertically flipping images to increase the diversity of object appearances.
- Noise Addition: Introducing random noise to emulate real-world image imperfections and enhance the model's robustness against noisy inputs.
- Location:
/content/drive/MyDrive/Project/Real photos/ - Format: Includes various image formats such as
.jpg,.jpeg,.png,.bmp,.gif, and.heic. - Description: A diverse set of images used to train and evaluate the YOLOv8 model for object detection.
-
File:
data.yaml -
Contents:
train: ../train/images val: ../valid/images test: ../test/images nc: 5 names: ['Bottle', 'HelloPanda', 'Potato_sticks', 'Rita_zero_sugar', 'Salt'] roboflow: workspace: project-c6dcl project: object_detection-xngop version: 2 license: CC BY 4.0 url: https://universe.roboflow.com/project-c6dcl/object_detection-xngop/dataset/2
- Version : Ultralytics YOLOv8 8.3.70
- Parameters : 43,610,463
- GFLOPs : 164.8
- Layers : 268
- PyTorch Model :
best.pt(86 MB) - ONNX Models :
yolov8_large_model.onnx(166.6 MB)
-
Install Dependencies :
pip install ultralytics
-
Training Command :
from ultralytics import YOLO project_dir = '/content/drive/MyDrive/Project' data_config = os.path.join(project_dir, 'data', 'object_detection_yolov8', 'data.yaml') model = YOLO('yolov8l.pt') # Use YOLOv8 large pre-trained weights model.train(data=data_config, epochs=100, patience=10)
project_dir = '/content/drive/MyDrive/Project'
data_config = os.path.join(project_dir, 'data', 'object_detection_yolov8', 'data.yaml') model = YOLO('yolov8l.pt') # Use YOLOv8 large pre-trained weights
model.train(data=data_config, epochs=100, patience=10)- Prevent Overfitting : Implement early stopping based on validation performance.
- Regularization : Apply weight decay and dropout where applicable.
- Cross-Validation : Utilize K-Fold cross-validation to ensure model generalization.
We perform inference on sample JPG images from the Real photos folder and visualize the results to verify that both our custom-trained and Roboflow-trained models achieve similar accuracy.
- Model Loading : Load the trained YOLOv8 model(s).
- Image Selection : Choose sample images (JPG) from the dataset.
- Run Inference : Obtain predictions (bounding boxes, class labels, confidence scores).
- Visualization : Display the annotated images with bounding boxes and labels.
- Comparison : Cross-check the predictions from both models side-by-side.
- Custom Model : Loaded from
/runs/detect/train5/weights/best.pt. - Roboflow Model : Loaded from its respective path.
- Visualization : Both modelsβ outputs are displayed on the same test image for comparison.
- Prediction Details : The console prints out the detected class names, confidence scores, and bounding box coordinates for each model.
To further improve detection accuracy and performance, consider the following:
- Data Augmentation : We trained both with and without Augmentation Rotate, scale, adjust brightness/contrast, and flip images.
- Hyperparameter Tuning : Adjust learning rates, batch sizes, and image sizes.
- Transfer Learning : Leverage pre-trained models and fine-tune them on your dataset.
- Advanced Post-Processing : Apply Non-Maximum Suppression (NMS) with fine-tuned IoU thresholds.
- ONNX Optimization : Simplify and quantize the ONNX model to reduce size and improve inference speed.
- File Not Found Errors : Ensure that the paths to the model and data are correct.
- Conversion Errors : Verify that HEIC files are valid and that required packages (
pyheif,Pillow) are installed. - Inference Crashes : Check resource availability and consider using GPU acceleration in Colab.
- Runtime Environment : Use Google Colabβs GPU accelerator for faster inference.
- Logging : Monitor outputs and error messages for debugging.
- Community Support : Consult the Ultralytics Forums or GitHub Issues for help.
Contributions are welcome! To contribute:
- Fork the Repository
- Create a New Branch :
git checkout -b feature/YourFeature - Commit Your Changes :
git commit -m "Add Your Feature" - Push and Open a Pull Request
This project is distributed under the MIT License. See the iotech file for more details.
- Your Name : [nawazktk99@gmail.com](Email Me "Email Me")
- GitHub : https://www.github.com/Aliktk/iotech
β¨ Thank you for checking out the YOLOv8 Object Detection Project! Happy detecting!