Upload 8 files
Browse files- README.dataset.txt +6 -0
- README.roboflow.txt +27 -0
- best.pt +3 -0
- data.yaml +6 -0
- detect_helmet.py +59 -0
- test_image.py +27 -0
- train_model.py +27 -0
- yolov8n.pt +3 -0
README.dataset.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Helmet & No helmet detection > 2025-12-20 5:14pm
|
| 2 |
+
https://universe.roboflow.com/saad-n/helmet-no-helmet-detection-f1heo
|
| 3 |
+
|
| 4 |
+
Provided by a Roboflow user
|
| 5 |
+
License: MIT
|
| 6 |
+
|
README.roboflow.txt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
Helmet & No helmet detection - v1 2025-12-20 5:14pm
|
| 3 |
+
==============================
|
| 4 |
+
|
| 5 |
+
This dataset was exported via roboflow.com on December 20, 2025 at 12:14 PM GMT
|
| 6 |
+
|
| 7 |
+
Roboflow is an end-to-end computer vision platform that helps you
|
| 8 |
+
* collaborate with your team on computer vision projects
|
| 9 |
+
* collect & organize images
|
| 10 |
+
* understand and search unstructured image data
|
| 11 |
+
* annotate, and create datasets
|
| 12 |
+
* export, train, and deploy computer vision models
|
| 13 |
+
* use active learning to improve your dataset over time
|
| 14 |
+
|
| 15 |
+
For state of the art Computer Vision training notebooks you can use with this dataset,
|
| 16 |
+
visit https://github.com/roboflow/notebooks
|
| 17 |
+
|
| 18 |
+
To find over 100k other datasets and pre-trained models, visit https://universe.roboflow.com
|
| 19 |
+
|
| 20 |
+
The dataset includes 984 images.
|
| 21 |
+
-Helmet-Bald-Hair-Cap are annotated in YOLOv8 format.
|
| 22 |
+
|
| 23 |
+
The following pre-processing was applied to each image:
|
| 24 |
+
|
| 25 |
+
No image augmentation techniques were applied.
|
| 26 |
+
|
| 27 |
+
|
best.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9e321aea22208bfa37b73649dc5c5d1e2d855c140c5055ee002859975a7cc192
|
| 3 |
+
size 18461987
|
data.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
train: train/images
|
| 2 |
+
val: valid/images
|
| 3 |
+
test: test/images
|
| 4 |
+
|
| 5 |
+
nc: 6
|
| 6 |
+
names: ['1-2-helmet', '3-4-helmet', 'Bald', 'Cap', 'Face and Hair', 'Full-face-helmet']
|
detect_helmet.py
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# --- Path Configuration ---
|
| 6 |
+
# Training khatam hone par model 'train2' folder mein banega
|
| 7 |
+
BEST_MODEL_PATH = 'best.pt'
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
# 1. Load your custom trained model
|
| 11 |
+
if not os.path.exists(BEST_MODEL_PATH):
|
| 12 |
+
print(f"Waiting for model... File not found at {BEST_MODEL_PATH}")
|
| 13 |
+
print("Training khatam hone ka intezar karein.")
|
| 14 |
+
else:
|
| 15 |
+
model = YOLO(BEST_MODEL_PATH)
|
| 16 |
+
|
| 17 |
+
# Categories based on your data.yaml
|
| 18 |
+
SAFE_CLASSES = ['1-2-helmet', '3-4-helmet', 'Full-face-helmet']
|
| 19 |
+
WARNING_CLASSES = ['Bald', 'Cap', 'Face and Hair']
|
| 20 |
+
|
| 21 |
+
cap = cv2.VideoCapture(0) # Webcam open karein
|
| 22 |
+
|
| 23 |
+
print("System Started. Press 'q' to quit.")
|
| 24 |
+
|
| 25 |
+
while cap.isOpened():
|
| 26 |
+
ret, frame = cap.read()
|
| 27 |
+
if not ret: break
|
| 28 |
+
|
| 29 |
+
# Detection shuru
|
| 30 |
+
results = model.predict(source=frame, conf=0.50, stream=True)
|
| 31 |
+
|
| 32 |
+
for result in results:
|
| 33 |
+
names = result.names
|
| 34 |
+
for box in result.boxes:
|
| 35 |
+
class_id = int(box.cls[0])
|
| 36 |
+
conf = float(box.conf[0])
|
| 37 |
+
label_name = names[class_id]
|
| 38 |
+
|
| 39 |
+
x1, y1, x2, y2 = map(int, box.xyxy[0])
|
| 40 |
+
|
| 41 |
+
# Color logic
|
| 42 |
+
if label_name in SAFE_CLASSES:
|
| 43 |
+
color = (0, 255, 0) # Green for SAFE
|
| 44 |
+
msg = f"SAFE: {label_name} {conf:.2f}"
|
| 45 |
+
elif label_name in WARNING_CLASSES:
|
| 46 |
+
color = (0, 0, 255) # Red for WARNING
|
| 47 |
+
msg = f"WARNING: No Helmet ({label_name}) {conf:.2f}"
|
| 48 |
+
else:
|
| 49 |
+
color = (255, 255, 255) # White for others
|
| 50 |
+
msg = f"{label_name} {conf:.2f}"
|
| 51 |
+
|
| 52 |
+
cv2.rectangle(frame, (x1, y1), (x2, y2), color, 3)
|
| 53 |
+
cv2.putText(frame, msg, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, color, 2)
|
| 54 |
+
|
| 55 |
+
cv2.imshow("Helmet Detection Final Assignment", frame)
|
| 56 |
+
if cv2.waitKey(1) & 0xFF == ord('q'): break
|
| 57 |
+
|
| 58 |
+
cap.release()
|
| 59 |
+
cv2.destroyAllWindows()
|
test_image.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# test_image.py
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
import cv2
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
# Training ke baad wala model path
|
| 7 |
+
model_path = 'runs/detect/train2/weights/best.pt'
|
| 8 |
+
|
| 9 |
+
if os.path.exists(model_path):
|
| 10 |
+
model = YOLO(model_path)
|
| 11 |
+
|
| 12 |
+
# Dataset ke test folder mein se kisi image ka path
|
| 13 |
+
# Aap manually koi bhi image ka path yahan paste kar sakte hain
|
| 14 |
+
img_path = input("Enter image path (e.g., test/images/1.jpg): ")
|
| 15 |
+
|
| 16 |
+
if os.path.exists(img_path):
|
| 17 |
+
results = model(img_path)
|
| 18 |
+
|
| 19 |
+
for r in results:
|
| 20 |
+
im_array = r.plot() # Detection draw karega
|
| 21 |
+
cv2.imshow('Final Test', im_array)
|
| 22 |
+
cv2.waitKey(0) # Press any key to close
|
| 23 |
+
cv2.destroyAllWindows()
|
| 24 |
+
else:
|
| 25 |
+
print("Image file nahi mili! Path check karein.")
|
| 26 |
+
else:
|
| 27 |
+
print("Model abhi tak train nahi hua. Training khatam hone ka intezar karein.")
|
train_model.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from ultralytics import YOLO
|
| 2 |
+
import os
|
| 3 |
+
|
| 4 |
+
# --- Configurations ---
|
| 5 |
+
DATA_YAML_PATH = 'data.yaml'
|
| 6 |
+
# Ye path confirm kar lein ke aapke folder structure ke mutabiq sahi ho.
|
| 7 |
+
# Maslan agar Helmet - No helmet detection.v1i.yolov8 folder C drive mein hai,
|
| 8 |
+
# toh uska pura path de sakte hain: 'C:/Users/YourName/.../data.yaml'
|
| 9 |
+
|
| 10 |
+
EPOCHS = 50 # Behtar accuracy ke liye 50 epochs
|
| 11 |
+
|
| 12 |
+
# 1. Load a pretrained YOLOv8n model
|
| 13 |
+
model = YOLO('yolov8n.pt')
|
| 14 |
+
|
| 15 |
+
# 2. Train the model
|
| 16 |
+
print(f"Starting training with data from: {DATA_YAML_PATH}")
|
| 17 |
+
if not os.path.exists(DATA_YAML_PATH):
|
| 18 |
+
print(f"ERROR: data.yaml file not found at {DATA_YAML_PATH}")
|
| 19 |
+
print("Please make sure the path is correct and the file exists.")
|
| 20 |
+
else:
|
| 21 |
+
results = model.train(
|
| 22 |
+
data=DATA_YAML_PATH,
|
| 23 |
+
epochs=EPOCHS,
|
| 24 |
+
imgsz=640,
|
| 25 |
+
plots=True
|
| 26 |
+
)
|
| 27 |
+
print("Training completed! Check 'runs/detect/train/weights/best.pt' for your trained model.")
|
yolov8n.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f59b3d833e2ff32e194b5bb8e08d211dc7c5bdf144b90d2c8412c47ccfc83b36
|
| 3 |
+
size 6549796
|