YAML Metadata Warning:empty or missing yaml metadata in repo card

Check out the documentation for more information.

πŸͺ– Helmet Detection using YOLOv8

This project detects whether riders are wearing helmets using a pre-trained YOLOv8 model. It can process both videos and real-time webcam feeds to identify helmet usage among bikers. The output video is saved with detection boxes labeled as "Helmet" or "No Helmet".


πŸ“Έ Demo

Example detection results on bikers --- showing bounding boxes for helmet and no helmet riders. Without Helmet image

With Helmet

image

πŸš€ Features

  • Detects helmet and no helmet on motorbike riders.
  • Works with video files or live webcam.
  • Saves output video automatically.
  • Uses a pre-trained model from Hugging Face.

🧠 Model Details

  • Model Type: YOLOv8
  • Source: Hugging Face --- sharathhhhh/safetyHelmet-detection-yolov8
  • Framework: Ultralytics YOLOv8
  • Format: .pt (PyTorch weights)
  • Task: Object Detection

🧰 Setup Instructions (Google Colab)

1. Install Dependencies

!pip install ultralytics

2. Mount Google Drive

from google.colab import drive
drive.mount('/content/drive')

3. Import YOLO

from ultralytics import YOLO

4. Load and Run the Model on Video

model = YOLO('/content/drive/MyDrive/safetyHelmet.pt')

results = model.predict(
    source='/content/drive/MyDrive/helmet_test.mp4',
    conf=0.4,
    save=True,
    project='/content/drive/MyDrive/',
    name='helmet_output'
)

The output video will be saved in /content/drive/MyDrive/helmet_output/.

5. View Output Video Inline

from IPython.display import HTML
from base64 import b64encode

mp4 = open('/content/drive/MyDrive/helmet_output/helmet_test.mp4','rb').read()
data_url = "data:video/mp4;base64," + b64encode(mp4).decode()
HTML(f'<video width=700 controls><source src="{data_url}" type="video/mp4"></video>')

πŸ–₯️ Real-time Detection (Optional)

To use your webcam in Colab or a local Python script:

import cv2
from ultralytics import YOLO

model = YOLO('/content/drive/MyDrive/safetyHelmet.pt')
cap = cv2.VideoCapture(0)

while True:
    ret, frame = cap.read()
    if not ret:
        break
    results = model(frame)
    annotated_frame = results[0].plot()
    cv2.imshow("Helmet Detection", annotated_frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

πŸ“¦ Folder Structure

πŸ“‚ Helmet-Detection-YOLOv8
 ┣ πŸ“œ README.md
 ┣ πŸ“œ safetyHelmet.pt
 ┣ πŸ“œ helmet_test.mp4
 ┣ πŸ“œ detect_helmet.py
 β”— πŸ“‚ helmet_output/

πŸ§‘β€πŸ’» Author

Fatima Noor
BSCS Graduate | AI/ML Enthusiast | Computer Vision Developer


This project is open-source and available for educational and research purposes.

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support