File size: 3,321 Bytes
18d5a7c e919b68 c63d4c3 e919b68 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
---
license: cc-by-nc-sa-4.0
pipeline_tag: object-detection
tags:
- yolov8
- object-detection
datasets:
- MichalMlodawski/closed-open-eyes
language:
- en
---
**Links to Space:**
https://huggingface.co/spaces/MichalMlodawski/closed-open-eyes-detection
**Eval:**
| Epoch | Train Box Loss | Train Cls Loss | Train DFL Loss | Precision (B) | Recall (B) | mAP50 (B) | mAP50-95 (B) | Val Box Loss | Val Cls Loss | Val DFL Loss | 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 |
**Example code to run the model:**
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:
# Path to the results directory
results_path = os.path.join(test_images_path, 'result')
# Create the results folder
os.makedirs(results_path, exist_ok=True)
logging.info(f'Created results directory: {results_path}')
# Load the model
model = YOLO(model_path)
logging.info(f'Loaded model from: {model_path}')
# Process images
for img_file in Path(test_images_path).glob('*.*'):
if img_file.suffix.lower() in ['.jpg', '.jpeg', '.png']: # Supports JPG, JPEG, and PNG formats
logging.info(f'Processing file: {img_file}')
# Detect objects in the image
results = model(img_file)
for result in results:
# Get the result image with detections drawn
result_img = result.plot()
# Save the result image to the results_path folder
result_image_path = os.path.join(results_path, img_file.name)
cv2.imwrite(result_image_path, result_img)
logging.info(f'Saved result image to: {result_image_path}')
logging.info("Image processing completed.")
except Exception as e:
logging.error(f'An error occurred: {e}')
def main():
parser = argparse.ArgumentParser(description='Process images using YOLO model.')
parser.add_argument('model_path', type=str, help='Path to the YOLO model.')
parser.add_argument('test_images_path', type=str, help='Path to the directory containing test images.')
args = parser.parse_args()
setup_logging()
process_images(args.model_path, args.test_images_path)
if __name__ == "__main__":
main()
**Command to run the program:**
python script_name.py path/to/your/yolo_model.pt path/to/test/images
|