Spaces:
Sleeping
Sleeping
✅ [Pass] test with lower system requirements
Browse files- yolo/tools/data_loader.py +7 -1
- yolo/utils/model_utils.py +3 -2
yolo/tools/data_loader.py
CHANGED
|
@@ -3,7 +3,6 @@ from queue import Empty, Queue
|
|
| 3 |
from threading import Event, Thread
|
| 4 |
from typing import Generator, List, Tuple, Union
|
| 5 |
|
| 6 |
-
import cv2
|
| 7 |
import numpy as np
|
| 8 |
import torch
|
| 9 |
from loguru import logger
|
|
@@ -222,6 +221,8 @@ class StreamDataLoader:
|
|
| 222 |
self.stop_event = Event()
|
| 223 |
|
| 224 |
if self.is_stream:
|
|
|
|
|
|
|
| 225 |
self.cap = cv2.VideoCapture(self.source)
|
| 226 |
else:
|
| 227 |
self.queue = Queue()
|
|
@@ -251,6 +252,8 @@ class StreamDataLoader:
|
|
| 251 |
self.process_frame(image)
|
| 252 |
|
| 253 |
def load_video_file(self, video_path):
|
|
|
|
|
|
|
| 254 |
cap = cv2.VideoCapture(video_path)
|
| 255 |
while self.running:
|
| 256 |
ret, frame = cap.read()
|
|
@@ -261,6 +264,9 @@ class StreamDataLoader:
|
|
| 261 |
|
| 262 |
def process_frame(self, frame):
|
| 263 |
if isinstance(frame, np.ndarray):
|
|
|
|
|
|
|
|
|
|
| 264 |
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 265 |
frame = Image.fromarray(frame)
|
| 266 |
origin_frame = frame
|
|
|
|
| 3 |
from threading import Event, Thread
|
| 4 |
from typing import Generator, List, Tuple, Union
|
| 5 |
|
|
|
|
| 6 |
import numpy as np
|
| 7 |
import torch
|
| 8 |
from loguru import logger
|
|
|
|
| 221 |
self.stop_event = Event()
|
| 222 |
|
| 223 |
if self.is_stream:
|
| 224 |
+
import cv2
|
| 225 |
+
|
| 226 |
self.cap = cv2.VideoCapture(self.source)
|
| 227 |
else:
|
| 228 |
self.queue = Queue()
|
|
|
|
| 252 |
self.process_frame(image)
|
| 253 |
|
| 254 |
def load_video_file(self, video_path):
|
| 255 |
+
import cv2
|
| 256 |
+
|
| 257 |
cap = cv2.VideoCapture(video_path)
|
| 258 |
while self.running:
|
| 259 |
ret, frame = cap.read()
|
|
|
|
| 264 |
|
| 265 |
def process_frame(self, frame):
|
| 266 |
if isinstance(frame, np.ndarray):
|
| 267 |
+
# TODO: we don't need cv2
|
| 268 |
+
import cv2
|
| 269 |
+
|
| 270 |
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
|
| 271 |
frame = Image.fromarray(frame)
|
| 272 |
origin_frame = frame
|
yolo/utils/model_utils.py
CHANGED
|
@@ -92,8 +92,9 @@ def get_device(device_spec: Union[str, int, List[int]]) -> torch.device:
|
|
| 92 |
if isinstance(device_spec, (list, ListConfig)):
|
| 93 |
ddp_flag = True
|
| 94 |
device_spec = initialize_distributed()
|
| 95 |
-
|
| 96 |
-
|
|
|
|
| 97 |
|
| 98 |
|
| 99 |
class PostProccess:
|
|
|
|
| 92 |
if isinstance(device_spec, (list, ListConfig)):
|
| 93 |
ddp_flag = True
|
| 94 |
device_spec = initialize_distributed()
|
| 95 |
+
if torch.cuda.is_available() and "cuda" in str(device_spec):
|
| 96 |
+
return torch.device(device_spec), ddp_flag
|
| 97 |
+
return torch.device("cpu"), False
|
| 98 |
|
| 99 |
|
| 100 |
class PostProccess:
|