Spaces:
Runtime error
Runtime error
Sync CUDA before timing for accurate runtime
Browse files- app/safety.py +6 -0
app/safety.py
CHANGED
|
@@ -7,6 +7,7 @@ import time
|
|
| 7 |
|
| 8 |
import cv2
|
| 9 |
import numpy as np
|
|
|
|
| 10 |
from PIL import Image
|
| 11 |
|
| 12 |
from .config import IMAGE_EXTS
|
|
@@ -405,6 +406,11 @@ class SafetyAnalyzer:
|
|
| 405 |
seg_mask_union=seg_mask_union,
|
| 406 |
hazard_mask=hazard_mask,
|
| 407 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 408 |
runtime_ms = (time.perf_counter() - t0) * 1000.0
|
| 409 |
safe_area_pct = float(safe_display_mask.mean()) * 100.0
|
| 410 |
hazard_pct = 100.0 - safe_area_pct
|
|
|
|
| 7 |
|
| 8 |
import cv2
|
| 9 |
import numpy as np
|
| 10 |
+
import torch
|
| 11 |
from PIL import Image
|
| 12 |
|
| 13 |
from .config import IMAGE_EXTS
|
|
|
|
| 406 |
seg_mask_union=seg_mask_union,
|
| 407 |
hazard_mask=hazard_mask,
|
| 408 |
)
|
| 409 |
+
try:
|
| 410 |
+
if torch.cuda.is_available():
|
| 411 |
+
torch.cuda.synchronize()
|
| 412 |
+
except Exception:
|
| 413 |
+
pass
|
| 414 |
runtime_ms = (time.perf_counter() - t0) * 1000.0
|
| 415 |
safe_area_pct = float(safe_display_mask.mean()) * 100.0
|
| 416 |
hazard_pct = 100.0 - safe_area_pct
|