Skip to content

Commit 882717b

Browse files
committed
Use PoseBackends enum for backend field
Add a PoseBackends Enum and switch PoseSource.backend from a string to that enum for stronger typing and clarity. Update default PosePacket/PoseSource instances and the validate_pose_array signature to use PoseBackends.DLC_LIVE. Import Enum/auto and remove an unused sentinel variable. These are small refactors to improve type-safety and consistency around backend identification.
1 parent 990654b commit 882717b

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

dlclivegui/services/dlc_processor.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from collections import deque
1111
from contextlib import contextmanager
1212
from dataclasses import dataclass
13+
from enum import Enum, auto
1314
from typing import Any
1415

1516
import numpy as np
@@ -33,6 +34,10 @@
3334
DLCLive = None # type: ignore[assignment]
3435

3536

37+
class PoseBackends(Enum):
38+
DLC_LIVE = auto()
39+
40+
3641
@dataclass
3742
class PoseResult:
3843
pose: np.ndarray | None
@@ -42,7 +47,7 @@ class PoseResult:
4247

4348
@dataclass(slots=True, frozen=True)
4449
class PoseSource:
45-
backend: str # e.g. "DLCLive"
50+
backend: PoseBackends # e.g. "DLCLive"
4651
model_type: ModelType | None = None
4752

4853

@@ -52,11 +57,11 @@ class PosePacket:
5257
keypoints: np.ndarray | None = None
5358
keypoint_names: list[str] | None = None
5459
individual_ids: list[str] | None = None
55-
source: PoseSource = PoseSource(backend="DLCLive")
60+
source: PoseSource = PoseSource(backend=PoseBackends.DLC_LIVE)
5661
raw: Any | None = None
5762

5863

59-
def validate_pose_array(pose: Any, *, source_backend: str = "DLCLive") -> np.ndarray:
64+
def validate_pose_array(pose: Any, *, source_backend: PoseBackends = PoseBackends.DLC_LIVE) -> np.ndarray:
6065
"""
6166
Validate pose output shape and dtype.
6267
@@ -120,9 +125,6 @@ class ProcessorStats:
120125
avg_processor_overhead: float = 0.0 # Socket processor overhead
121126

122127

123-
# _SENTINEL = object()
124-
125-
126128
class DLCLiveProcessor(QObject):
127129
"""Background pose estimation using DLCLive with queue-based threading."""
128130

@@ -337,7 +339,7 @@ def _process_frame(
337339
keypoints=pose_arr,
338340
keypoint_names=None,
339341
individual_ids=None,
340-
source=PoseSource(backend="DLCLive", model_type=self._settings.model_type),
342+
source=PoseSource(backend=PoseBackends.DLC_LIVE, model_type=self._settings.model_type),
341343
raw=raw_pose,
342344
)
343345

0 commit comments

Comments
 (0)