ONNX Model Zoo

luisarizmendi/hardhat-or-hat

By luisarizmendi · ↓ 0 · ♥ 0 · Updated 2025-04-24

What's in this repo

This page lists the files in luisarizmendi/hardhat-or-hat, including model.onnx and more.

  • 2 ONNX models (.onnx files)
  • 86 files, including 40 .jpg, 28 .png, 2 .ipynb, 2 .py, 2 .onnx, 2 .pt
  • Last updated 2025-04-24

ONNX files

File Size Download
v1/model/onnx/1/model.onnx — Download
v2/model/onnx/1/model.onnx — Download

How to use

These ONNX files can be loaded with ONNX Runtime. To inspect a model graph, upload the file to the Netron viewer. Download links point to the original files on Hugging Face.

README

Model for detecting Hardhats and Hats

luisarizmendi/hardhat-or-hat

Model binary

You can download:

Base Model

Ultralytics/YOLO11m

Huggingface page

https://huggingface.co/luisarizmendi/hardhat-or-hat

Model Dataset

https://universe.roboflow.com/luisarizmendi/hardhat-or-hat

Labels

- hat
- helmet
- no_helmet

Model metrics

luisarizmendi/hardhat-or-hat

luisarizmendi/hardhat-or-hat

Model training

You can review the Jupyter notebook here

Hyperparameters

base model: yolov11x.pt
epochs: 150
batch: 16
imgsz: 640
patience: 15
optimizer: 'SGD'
lr0: 0.001
lrf: 0.01
momentum: 0.9
weight_decay: 0.0005
warmup_epochs: 3
warmup_bias_lr: 0.01
warmup_momentum: 0.8

Model Usage

Usage with Huggingface spaces

If you don't want to run it locally, you can use this huggingface space that I've created with this code but be aware that this will be slow since I'm using a free instance, so it's better to run it locally with the python script below.

Remember to check that the Model URL is pointing to the model that you want to test.

luisarizmendi/hardhat-or-hat

Usage with Python script

Install the following PIP requirements

gradio
ultralytics
Pillow
opencv-python
torch

Then run the python code below and open http://localhost:8800 in a browser to upload and scan the images.

import gradio as gr
from ultralytics import YOLO
from PIL import Image
import os
import cv2
import torch

DEFAULT_MODEL_URL = "https://huggingface.co/luisarizmendi/hardhat-or-hat/tree/main/v2/model/pytorch/best.pt"

def detect_objects_in_files(model_input, files):
    """
    Processes uploaded images for object detection.
    """
    if not files:
        return "No files uploaded.", []

    model = YOLO(str(model_input))
    if torch.cuda.is_available():
        model.to('cuda')
        print("Using GPU for inference")
    else:
        print("Using CPU for inference")

    results_images = []
    for file in files:
        try:
            image = Image.open(file).convert("RGB")
            results = model(image)
            result_img_bgr = results[0].plot()
            result_img_rgb = cv2.cvtColor(result_img_bgr, cv2.COLOR_BGR2RGB)
            results_images.append(result_img_rgb)

            # If you want that images appear one by one (slower)
            #yield "Processing image...", results_images

        except Exception as e:
            return f"Error processing file: {file}. Exception: {str(e)}", []

    del model
    torch.cuda.empty_cache()

    return "Processing completed.", results_images

interface = gr.Interface(
    fn=detect_objects_in_files,
    inputs=[
        gr.Textbox(value=DEFAULT_MODEL_URL, label="Model URL", placeholder="Enter the model URL"),
        gr.Files(file_types=["image"], label="Select Images"),
    ],
    outputs=[
        gr.Textbox(label="Status"),
        gr.Gallery(label="Results")
    ],
    title="Object Detection on Images",
    description="Upload images to perform object detection. The model will process each image and display the results."
)

if __name__ == "__main__":
    interface.launch()

Model info

tensorboard onnx yolo yolo11 hardhat hat object-detection base_model:Ultralytics/YOLO11 base_model:quantized:Ultralytics/YOLO11 model-index region:us
↓ 0 ♥ 0

Created: 2024-11-28

Updated: 2025-04-24

View on Hugging Face

Files (86)

.gitattributes
.ipynb_checkpoints/train-checkpoint.ipynb
README.md
dev/object-detection-model-file/pytorch/Containerfile
dev/object-detection-model-file/pytorch/object-detection-pytorch.py
dev/object-detection-model-file/pytorch/requirements.txt
dev/prototyping.ipynb
images/example.png
images/spaces-example.png
tools/pytorch-to-onnx.py
v1/model/onnx/1/model.onnx ONNX
v1/model/pytorch/best.pt
v1/test/F1_curve.png
v1/test/PR_curve.png
v1/test/P_curve.png
v1/test/R_curve.png
v1/test/confusion_matrix.png
v1/test/confusion_matrix_normalized.png
v1/test/val_batch0_labels.jpg
v1/test/val_batch0_pred.jpg
v1/test/val_batch1_labels.jpg
v1/test/val_batch1_pred.jpg
v1/test/val_batch2_labels.jpg
v1/test/val_batch2_pred.jpg
v1/train-val/F1_curve.png
v1/train-val/PR_curve.png
v1/train-val/P_curve.png
v1/train-val/R_curve.png
v1/train-val/args.yaml
v1/train-val/confusion_matrix.png
v1/train-val/confusion_matrix_normalized.png
v1/train-val/events.out.tfevents.1738747289.yolo-training-pipeline-7vd94-system-container-impl-3115668440.58.0
v1/train-val/labels.jpg
v1/train-val/labels_correlogram.jpg
v1/train-val/results.csv
v1/train-val/results.png
v1/train-val/train_batch0.jpg
v1/train-val/train_batch1.jpg
v1/train-val/train_batch2.jpg
v1/train-val/train_batch27555.jpg
v1/train-val/train_batch27556.jpg
v1/train-val/train_batch27557.jpg
v1/train-val/val_batch0_labels.jpg
v1/train-val/val_batch0_pred.jpg
v1/train-val/val_batch1_labels.jpg
v1/train-val/val_batch1_pred.jpg
v1/train-val/val_batch2_labels.jpg
v1/train-val/val_batch2_pred.jpg
v2/model/onnx/1/model.onnx ONNX
v2/model/pytorch/best.pt
v2/test/F1_curve.png
v2/test/PR_curve.png
v2/test/P_curve.png
v2/test/R_curve.png
v2/test/confusion_matrix.png
v2/test/confusion_matrix_normalized.png
v2/test/val_batch0_labels.jpg
v2/test/val_batch0_pred.jpg
v2/test/val_batch1_labels.jpg
v2/test/val_batch1_pred.jpg
v2/test/val_batch2_labels.jpg
v2/test/val_batch2_pred.jpg
v2/train-val/F1_curve.png
v2/train-val/PR_curve.png
v2/train-val/P_curve.png
v2/train-val/R_curve.png
v2/train-val/args.yaml
v2/train-val/confusion_matrix.png
v2/train-val/confusion_matrix_normalized.png
v2/train-val/events.out.tfevents.1738747287.yolo-training-pipeline-b82kg-system-container-impl-2306871192.63.0
v2/train-val/labels.jpg
v2/train-val/labels_correlogram.jpg
v2/train-val/results.csv
v2/train-val/results.png
v2/train-val/train_batch0.jpg
v2/train-val/train_batch1.jpg
v2/train-val/train_batch2.jpg
v2/train-val/train_batch27555.jpg
v2/train-val/train_batch27556.jpg
v2/train-val/train_batch27557.jpg
v2/train-val/val_batch0_labels.jpg
v2/train-val/val_batch0_pred.jpg
v2/train-val/val_batch1_labels.jpg
v2/train-val/val_batch1_pred.jpg
v2/train-val/val_batch2_labels.jpg
v2/train-val/val_batch2_pred.jpg

Related models