Spaces:
Sleeping
Sleeping
Update yolo_detect.py
Browse files- yolo_detect.py +5 -4
yolo_detect.py
CHANGED
|
@@ -2,7 +2,6 @@ import sys
|
|
| 2 |
from ultralytics import YOLO
|
| 3 |
from pathlib import Path
|
| 4 |
import cv2
|
| 5 |
-
import os
|
| 6 |
|
| 7 |
if len(sys.argv) < 3:
|
| 8 |
print("Usage: python yolo_detect.py <weights_path> <media_path>")
|
|
@@ -36,17 +35,19 @@ def convert_avi_to_mp4(avi_path):
|
|
| 36 |
if media_path.lower().endswith(('.mp4', '.avi', '.mov', '.mkv', '.webm')):
|
| 37 |
# Video detection
|
| 38 |
results = model(media_path, save=True, project='/data/runs/detect', exist_ok=True)
|
| 39 |
-
|
| 40 |
for r in results:
|
| 41 |
for avi_path in Path(r.save_dir).glob("*.avi"):
|
| 42 |
if avi_path.is_file():
|
| 43 |
-
# Convert to mp4
|
| 44 |
mp4_path = convert_avi_to_mp4(avi_path)
|
| 45 |
print(str(mp4_path))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
else:
|
| 47 |
# Image detection
|
| 48 |
results = model(media_path, save=True, project='/data/runs/detect', exist_ok=True)
|
| 49 |
-
# Find the output image file
|
| 50 |
for r in results:
|
| 51 |
for path in Path(r.save_dir).glob("*"):
|
| 52 |
if path.is_file():
|
|
|
|
| 2 |
from ultralytics import YOLO
|
| 3 |
from pathlib import Path
|
| 4 |
import cv2
|
|
|
|
| 5 |
|
| 6 |
if len(sys.argv) < 3:
|
| 7 |
print("Usage: python yolo_detect.py <weights_path> <media_path>")
|
|
|
|
| 35 |
if media_path.lower().endswith(('.mp4', '.avi', '.mov', '.mkv', '.webm')):
|
| 36 |
# Video detection
|
| 37 |
results = model(media_path, save=True, project='/data/runs/detect', exist_ok=True)
|
| 38 |
+
found = False
|
| 39 |
for r in results:
|
| 40 |
for avi_path in Path(r.save_dir).glob("*.avi"):
|
| 41 |
if avi_path.is_file():
|
|
|
|
| 42 |
mp4_path = convert_avi_to_mp4(avi_path)
|
| 43 |
print(str(mp4_path))
|
| 44 |
+
found = True
|
| 45 |
+
if not found:
|
| 46 |
+
print("ERROR: No .avi file found for conversion.", file=sys.stderr)
|
| 47 |
+
sys.exit(1)
|
| 48 |
else:
|
| 49 |
# Image detection
|
| 50 |
results = model(media_path, save=True, project='/data/runs/detect', exist_ok=True)
|
|
|
|
| 51 |
for r in results:
|
| 52 |
for path in Path(r.save_dir).glob("*"):
|
| 53 |
if path.is_file():
|