feat: add governed nationwide AOI orchestration and CUDA enforcement
This commit is contained in:
@@ -38,6 +38,8 @@ class YoloDetectionAdapter:
|
||||
status_code=503,
|
||||
)
|
||||
|
||||
self.validate_runtime()
|
||||
|
||||
try:
|
||||
from ultralytics import YOLO
|
||||
except ImportError as exc:
|
||||
@@ -57,6 +59,32 @@ class YoloDetectionAdapter:
|
||||
status_code=503,
|
||||
) from exc
|
||||
|
||||
def validate_runtime(self) -> None:
|
||||
if not self.settings.yolo_require_cuda:
|
||||
return
|
||||
try:
|
||||
import torch
|
||||
except Exception as exc:
|
||||
raise AppError(
|
||||
code="DETECTION_ACCELERATOR_UNAVAILABLE",
|
||||
message="NVIDIA CUDA is required for configured YOLO inference, but PyTorch is not importable.",
|
||||
status_code=503,
|
||||
) from exc
|
||||
if not torch.cuda.is_available():
|
||||
raise AppError(
|
||||
code="DETECTION_ACCELERATOR_UNAVAILABLE",
|
||||
message="NVIDIA CUDA is required for configured YOLO inference, but no CUDA device is available.",
|
||||
details={"configured_device": self.settings.yolo_device},
|
||||
status_code=503,
|
||||
)
|
||||
if not str(self.settings.yolo_device).lower().startswith(("cuda", "0", "1", "2", "3")):
|
||||
raise AppError(
|
||||
code="DETECTION_ACCELERATOR_MISCONFIGURED",
|
||||
message="NVIDIA CUDA is required, but YOLO_DEVICE does not select a CUDA device.",
|
||||
details={"configured_device": self.settings.yolo_device},
|
||||
status_code=503,
|
||||
)
|
||||
|
||||
def predict_tile(self, model, tile_path: Path, confidence_threshold: float) -> list[dict[str, Any]]:
|
||||
if not tile_path.exists() or not tile_path.is_file():
|
||||
raise AppError(
|
||||
|
||||
Reference in New Issue
Block a user