Skip to content

Detection Engine

app.infrastructure.detection.engine.detection_engine

View source code

Application-facing model loading and frame-detection delegation.

The engine selects a provider through load_detection_model and returns that provider's results directly. Preprocessing, inference, and conversion to domain results belong to the BaseDetectionModel implementation, not this wrapper.

Layer: Infrastructure. Context: Implements concrete processing and I/O behind application-facing contracts.

DetectionEngine

Manage one model instance and delegate synchronous frame inference to it.

The generated API page lists registered model names. Model construction and inference run in the calling thread; application workers are responsible for keeping expensive operations off the GUI thread. This wrapper adds no synchronization or result copying.

Provider requirements

Real models may load or acquire weights and require compatible runtimes or hardware. Input handling and inference-failure behavior are provider-specific; some providers log failures and return an empty list.

Examples:

Given a NumPy frame prepared for the selected provider:

from app.infrastructure.detection.engine.detection_engine import DetectionEngine

engine = DetectionEngine("YOLOv8n")
detections = engine.detect(frame)
engine.set_model("YOLOv8s")

This illustrative example may require model weights; documentation builds do not execute it.

model_name: str property

Return the last model name assigned during initialization or switching.

RETURNS DESCRIPTION
str

Requested model name. After a failed switch, it can differ from

str

the name associated with the retained model instance.

__init__(model_name: str) -> None

PARAMETER DESCRIPTION
model_name

Registered model name, or "None" for the dummy model.

TYPE: str

RAISES DESCRIPTION
DetectionModelError

If the name is not registered.

Provider construction errors propagate without translation.

detect(frame: np.ndarray) -> list[DetectionResult]

Delegate one frame to the current provider without label selection.

PARAMETER DESCRIPTION
frame

Image array prepared for the selected provider. The model interface describes RGB input; this wrapper does not validate shape, dtype, channel order, or copy the array.

TYPE: ndarray

RETURNS DESCRIPTION
list[DetectionResult]

The provider's list of

list[DetectionResult]
list[DetectionResult]

objects, unchanged and without an additional copy. An empty list

list[DetectionResult]

may mean no detections or a failure handled by the provider.

Errors not handled by the provider propagate to the caller. This wrapper does not guarantee that inference leaves the supplied array unchanged.

set_model(model_name: str) -> None

Switch to a different detection model by model_name.

PARAMETER DESCRIPTION
model_name

Registered model name, or "None" for the dummy model.

TYPE: str

RAISES DESCRIPTION
DetectionModelError

If the name is not registered.

Provider construction errors also propagate.

A failed switch is not atomic

The name is assigned before loading. If loading fails, the previous model instance remains active but model_name reports the requested name. This method does not roll back the name or coordinate concurrent inference.

Supported models

This catalog is auto-generated from app.infrastructure.detection.model.names.

TorchVision

  • Torch FCOS_ResNet50_FPN
  • Torch FasterRCNN_MobileNet_V3_Large_320_FPN
  • Torch FasterRCNN_MobileNet_V3_Large_FPN
  • Torch FasterRCNN_ResNet50_FPN_V2
  • Torch FasterRCNN_ResNet50_FPN
  • Torch RetinaNet_ResNet50_FPN_V2
  • Torch RetinaNet_ResNet50_FPN
  • Torch SSD300_VGG16
  • Torch SSDLite320_MobileNet_V3_Large

Ultralytics YOLO

  • YOLOv3-tiny
  • YOLOv3
  • YOLOv3-spp
  • YOLOv5n
  • YOLOv5s
  • YOLOv5m
  • YOLOv5l
  • YOLOv5x
  • YOLOv8n
  • YOLOv8s
  • YOLOv8m
  • YOLOv8l
  • YOLOv8x
  • YOLOv9t
  • YOLOv9s
  • YOLOv9m
  • YOLOv9c
  • YOLOv9e
  • YOLOv10n
  • YOLOv10s
  • YOLOv10m
  • YOLOv10b
  • YOLOv10l
  • YOLOv10x
  • YOLO11n
  • YOLO11s
  • YOLO11m
  • YOLO11l
  • YOLO11x
  • YOLO12n
  • YOLO12s
  • YOLO12m
  • YOLO12l
  • YOLO12x
  • YOLOv26n
  • YOLOv26s
  • YOLOv26m
  • YOLOv26l
  • YOLOv26x

MTCNN

  • MTCNN-Tensorflow
  • MTCNN-Pytorch