Skip to content

Detection Engine

app.application.managers.detection_engine

View source code

Centralizes detection engine lifecycle (create / update / remove) per session.

See Also

Layer: Application. Context: Coordinates session-scoped lifecycles for application workers and resources.

DetectionEngineManager

Manages the lifecycle of DetectionEngine instances on a per-session basis.

Responsibilities
  • Create a new DetectionEngine when none exists for a session.
  • Update the loaded model in an existing DetectionEngine.
  • Remove (clear) the engine reference from a session.

This manager centralises the engine-creation logic that previously lived inside DetectionService._create_or_update_detection_engine_from_model_name_for_session_id, giving DetectionService a narrower single responsibility.

The session repository is injected, so the manager is independently unit-testable without a live Application instance.

PARAMETER DESCRIPTION
session_repo

Interface used to find a session and assign its detection engine.

TYPE: UIApplicationInterface

__init__(session_repo: UIApplicationInterface) -> None

create_or_update(s_id: SessionId, model_name: str) -> None

Create a new engine or update the model in an existing engine for s_id.

PARAMETER DESCRIPTION
s_id

Session ID of the target session.

TYPE: SessionId

model_name

YOLO model name to load (e.g. "yolov8n").

TYPE: str

Note

If the session has no engine yet, a new DetectionEngine is instantiated and assigned to session.detection_engine. If an engine already exists, its model is updated via DetectionEngine.set_model() to avoid unnecessary re-creation.

DetectionEngine is imported lazily to keep this module free of heavy infrastructure dependencies at import time.

remove(s_id: SessionId) -> None

Remove (clear) the detection engine reference for s_id.

PARAMETER DESCRIPTION
s_id

Session ID of the target session.

TYPE: SessionId

Note

Sets session.detection_engine to None. Any in-flight worker using that engine must be stopped before calling this.