Spaces:
Sleeping
Sleeping
Upload yolo_detect.py
Browse files- yolo_detect.py +19 -0
yolo_detect.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from ultralytics import YOLO
|
| 3 |
+
from pathlib import Path
|
| 4 |
+
|
| 5 |
+
if len(sys.argv) < 3:
|
| 6 |
+
print("Usage: python yolo_detect.py <weights_path> <image_path>")
|
| 7 |
+
sys.exit(1)
|
| 8 |
+
|
| 9 |
+
weights_path = sys.argv[1]
|
| 10 |
+
image_path = sys.argv[2]
|
| 11 |
+
|
| 12 |
+
model = YOLO(weights_path)
|
| 13 |
+
results = model(image_path, save=True, project='runs/detect', exist_ok=True)
|
| 14 |
+
|
| 15 |
+
# Print the path to the saved image
|
| 16 |
+
for r in results:
|
| 17 |
+
for path in Path(r.save_dir).glob("*"):
|
| 18 |
+
if path.is_file():
|
| 19 |
+
print(str(path))
|