Instructions to use dxvyaaa/yolo_helmet with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ultralytics
How to use dxvyaaa/yolo_helmet with ultralytics:
from ultralytics import YOLOvv8 model = YOLOvv8.from_pretrained("dxvyaaa/yolo_helmet") source = 'http://images.cocodataset.org/val2017/000000039769.jpg' model.predict(source=source, save=True) - YOLOv10
How to use dxvyaaa/yolo_helmet with YOLOv10:
from ultralytics import YOLOvv8 model = YOLOvv8.from_pretrained("dxvyaaa/yolo_helmet") source = 'http://images.cocodataset.org/val2017/000000039769.jpg' model.predict(source=source, save=True) - Notebooks
- Google Colab
- Kaggle
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,38 +1,34 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
-
import
|
| 4 |
|
| 5 |
-
|
|
|
|
| 6 |
|
| 7 |
def predict(image):
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
xmin, ymin, xmax, ymax = box.xyxy[0].tolist()
|
| 14 |
-
cls = int(box.cls)
|
| 15 |
-
conf = float(box.conf)
|
| 16 |
|
|
|
|
|
|
|
| 17 |
detections.append({
|
| 18 |
-
"label": model.names[cls],
|
| 19 |
-
"confidence": conf,
|
| 20 |
-
"box": [
|
| 21 |
})
|
| 22 |
|
| 23 |
-
|
| 24 |
-
except Exception as e:
|
| 25 |
-
print("ERROR:", e)
|
| 26 |
-
return image, []
|
| 27 |
|
|
|
|
| 28 |
demo = gr.Interface(
|
| 29 |
fn=predict,
|
| 30 |
-
inputs=gr.Image(type="numpy"
|
| 31 |
-
outputs=[
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
],
|
| 35 |
-
title="YOLO Helmet Detection"
|
| 36 |
)
|
| 37 |
|
| 38 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from ultralytics import YOLO
|
| 3 |
+
import numpy as np
|
| 4 |
|
| 5 |
+
# Load YOLOv8 model
|
| 6 |
+
model = YOLO("best.pt") # Make sure best.pt is in the repo root
|
| 7 |
|
| 8 |
def predict(image):
|
| 9 |
+
# image is numpy array from Gradio
|
| 10 |
+
results = model(image)[0] # YOLO prediction
|
| 11 |
|
| 12 |
+
annotated_image = results.plot() # returns numpy array
|
| 13 |
+
detections = []
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
if results.boxes is not None:
|
| 16 |
+
for box, cls, conf in zip(results.boxes.xyxy, results.boxes.cls, results.boxes.conf):
|
| 17 |
detections.append({
|
| 18 |
+
"label": model.names[int(cls)],
|
| 19 |
+
"confidence": float(conf),
|
| 20 |
+
"box": [float(coord) for coord in box]
|
| 21 |
})
|
| 22 |
|
| 23 |
+
return annotated_image, detections
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
# Gradio interface
|
| 26 |
demo = gr.Interface(
|
| 27 |
fn=predict,
|
| 28 |
+
inputs=gr.Image(type="numpy"),
|
| 29 |
+
outputs=[gr.Image(type="numpy"), gr.JSON()],
|
| 30 |
+
title="Helmet Detection YOLOv8",
|
| 31 |
+
description="Upload an image and detect helmet / head using YOLOv8"
|
|
|
|
|
|
|
| 32 |
)
|
| 33 |
|
| 34 |
demo.launch()
|