MichalMlodawski commited on
Commit
e919b68
1 Parent(s): 18d5a7c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +64 -1
README.md CHANGED
@@ -8,4 +8,67 @@ datasets:
8
  - MichalMlodawski/closed-open-eyes
9
  language:
10
  - en
11
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  - MichalMlodawski/closed-open-eyes
9
  language:
10
  - en
11
+ ---
12
+
13
+ **Example code to run the model:**
14
+
15
+ import os
16
+ from pathlib import Path
17
+ from ultralytics import YOLO
18
+ import cv2
19
+ import logging
20
+ import argparse
21
+
22
+ def setup_logging():
23
+ logging.basicConfig(level=logging.INFO,
24
+ format='%(asctime)s - %(levelname)s - %(message)s')
25
+
26
+ def process_images(model_path, test_images_path):
27
+ try:
28
+ # Path to the results directory
29
+ results_path = os.path.join(test_images_path, 'result')
30
+
31
+ # Create the results folder
32
+ os.makedirs(results_path, exist_ok=True)
33
+ logging.info(f'Created results directory: {results_path}')
34
+
35
+ # Load the model
36
+ model = YOLO(model_path)
37
+ logging.info(f'Loaded model from: {model_path}')
38
+
39
+ # Process images
40
+ for img_file in Path(test_images_path).glob('*.*'):
41
+ if img_file.suffix.lower() in ['.jpg', '.jpeg', '.png']: # Supports JPG, JPEG, and PNG formats
42
+ logging.info(f'Processing file: {img_file}')
43
+ # Detect objects in the image
44
+ results = model(img_file)
45
+
46
+ for result in results:
47
+ # Get the result image with detections drawn
48
+ result_img = result.plot()
49
+
50
+ # Save the result image to the results_path folder
51
+ result_image_path = os.path.join(results_path, img_file.name)
52
+ cv2.imwrite(result_image_path, result_img)
53
+ logging.info(f'Saved result image to: {result_image_path}')
54
+
55
+ logging.info("Image processing completed.")
56
+ except Exception as e:
57
+ logging.error(f'An error occurred: {e}')
58
+
59
+ def main():
60
+ parser = argparse.ArgumentParser(description='Process images using YOLO model.')
61
+ parser.add_argument('model_path', type=str, help='Path to the YOLO model.')
62
+ parser.add_argument('test_images_path', type=str, help='Path to the directory containing test images.')
63
+
64
+ args = parser.parse_args()
65
+ setup_logging()
66
+
67
+ process_images(args.model_path, args.test_images_path)
68
+
69
+ if __name__ == "__main__":
70
+ main()
71
+
72
+ **Command to run the program:**
73
+
74
+ python script_name.py path/to/your/yolo_model.pt path/to/test/images