ONNX 模型库
返回模型

说明文档

Space 链接: https://huggingface.co/spaces/MichalMlodawski/closed-open-eyes-detection

评估指标:

Epoch 训练框损失 训练分类损失 训练 DFL 损失 精确率 (B) 召回率 (B) mAP50 (B) mAP50-95 (B) 验证框损失 验证分类损失 验证 DFL 损失 LR PG0 LR PG1 LR PG2
100 1.0201 0.4718 0.84219 0.95394 0.93356 0.96767 0.66184 0.98246 0.45574 0.83703 0.000199 0.000199 0.000199

运行模型的示例代码:

import os
from pathlib import Path
from ultralytics import YOLO
import cv2
import logging
import argparse

def setup_logging():
    logging.basicConfig(level=logging.INFO, 
                        format='%(asctime)s - %(levelname)s - %(message)s')

def process_images(model_path, test_images_path):
    try:
        # 结果目录的路径
        results_path = os.path.join(test_images_path, 'result')
        
        # 创建结果文件夹
        os.makedirs(results_path, exist_ok=True)
        logging.info(f'已创建结果目录: {results_path}')
        
        # 加载模型
        model = YOLO(model_path)
        logging.info(f'已从以下路径加载模型: {model_path}')
        
        # 处理图像
        for img_file in Path(test_images_path).glob('*.*'):
            if img_file.suffix.lower() in ['.jpg', '.jpeg', '.png']:  # 支持 JPG、JPEG 和 PNG 格式
                logging.info(f'正在处理文件: {img_file}')
                # 检测图像中的对象
                results = model(img_file)
                
                for result in results:
                    # 获取绘制了检测结果的结果图像
                    result_img = result.plot()
                    
                    # 将结果图像保存到 results_path 文件夹
                    result_image_path = os.path.join(results_path, img_file.name)
                    cv2.imwrite(result_image_path, result_img)
                    logging.info(f'结果图像已保存至: {result_image_path}')
        
        logging.info("图像处理完成。")
    except Exception as e:
        logging.error(f'发生错误: {e}')

def main():
    parser = argparse.ArgumentParser(description='使用 YOLO 模型处理图像。')
    parser.add_argument('model_path', type=str, help='YOLO 模型的路径。')
    parser.add_argument('test_images_path', type=str, help='包含测试图像的目录路径。')
    
    args = parser.parse_args()
    setup_logging()
    
    process_images(args.model_path, args.test_images_path)

if __name__ == "__main__":
    main()

运行程序的命令:

python script_name.py path/to/your/yolo_model.pt path/to/test/images

MichalMlodawski/open-closed-eye-detection

作者 MichalMlodawski

object-detection
↓ 0 ♥ 1

创建时间: 2024-06-23 18:28:57+00:00

更新时间: 2024-06-23 18:58:06+00:00

在 Hugging Face 上查看

文件 (5)

.gitattributes
README.md
model.onnx ONNX
model.pt
model.safetensors