Skip to content

Commit ad6df3d

Browse files
committed
Extract shared inference base types
Move pose-related enums and dataclasses (PoseBackends, WorkerState, PoseSource, PosePacket, PoseResult) out of `dlc_processor.py` into a new `services/inference/base.py` module and import them back into the processor. This centralizes inference contracts for reuse and extends `PosePacket` with optional skeleton metadata fields (`skeleton_id`, `skeleton_edges`).
1 parent 0863c73 commit ad6df3d

3 files changed

Lines changed: 47 additions & 37 deletions

File tree

‎dlclivegui/services/dlc_processor.py‎

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
from collections import deque
1111
from contextlib import contextmanager
1212
from dataclasses import dataclass
13-
from enum import Enum, auto
1413
from typing import Any
1514

1615
import numpy as np
1716
from PySide6.QtCore import QObject, Signal
1817

19-
from dlclivegui.config import DLC_DO_LOG_TIMING, DLCProcessorSettings, ModelType
18+
from dlclivegui.config import DLC_DO_LOG_TIMING, DLCProcessorSettings
2019
from dlclivegui.processors.processor_utils import (
2120
ProcessorSpec,
2221
create_spec_from_scan,
@@ -28,6 +27,8 @@
2827
from dlclivegui.utils.stats import WorkerTimingStats
2928
from dlclivegui.utils.utils import format_thread_stack
3029

30+
from .inference.base import PoseBackends, PosePacket, PoseResult, PoseSource, WorkerState
31+
3132
logger = logging.getLogger(__name__)
3233
STOP_WORKER_TIMEOUT = 10.0 # # seconds to wait in STOPPING state before scheduling background reaping
3334

@@ -44,41 +45,6 @@
4445
ENABLE_PROFILING = False
4546

4647

47-
class PoseBackends(Enum):
48-
DLC_LIVE = auto()
49-
50-
51-
class WorkerState(Enum):
52-
STOPPED = auto()
53-
STARTING = auto()
54-
RUNNING = auto()
55-
STOPPING = auto()
56-
FAULTED = auto()
57-
58-
59-
@dataclass
60-
class PoseResult:
61-
pose: np.ndarray | None
62-
timestamp: float
63-
packet: PosePacket | None = None
64-
65-
66-
@dataclass(slots=True, frozen=True)
67-
class PoseSource:
68-
backend: PoseBackends # e.g. "DLCLive"
69-
model_type: ModelType | None = None
70-
71-
72-
@dataclass(slots=True, frozen=True)
73-
class PosePacket:
74-
schema_version: int = 0
75-
keypoints: np.ndarray | None = None
76-
keypoint_names: list[str] | None = None
77-
individual_ids: list[str] | None = None
78-
source: PoseSource = PoseSource(backend=PoseBackends.DLC_LIVE)
79-
raw: Any | None = None
80-
81-
8248
def validate_pose_array(
8349
pose: Any, *, source_backend: PoseBackends | str = PoseBackends.DLC_LIVE, check_finite: bool = True
8450
) -> np.ndarray:

‎dlclivegui/services/inference/__init__.py‎

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from dataclasses import dataclass
2+
from enum import Enum, auto
3+
from typing import Any
4+
5+
import numpy as np
6+
7+
from dlclivegui.config import ModelType
8+
9+
10+
class PoseBackends(Enum):
11+
DLC_LIVE = auto()
12+
13+
14+
class WorkerState(Enum):
15+
STOPPED = auto()
16+
STARTING = auto()
17+
RUNNING = auto()
18+
STOPPING = auto()
19+
FAULTED = auto()
20+
21+
22+
@dataclass(slots=True, frozen=True)
23+
class PoseSource:
24+
backend: PoseBackends # e.g. "DLCLive"
25+
model_type: ModelType | None = None
26+
27+
28+
@dataclass(slots=True, frozen=True)
29+
class PosePacket:
30+
schema_version: int = 0
31+
keypoints: np.ndarray | None = None
32+
keypoint_names: list[str] | None = None
33+
individual_ids: list[str] | None = None
34+
skeleton_id: str | None = None
35+
skeleton_edges: tuple[tuple[str, str], ...] | None = None
36+
source: PoseSource = PoseSource(backend=PoseBackends.DLC_LIVE)
37+
raw: Any | None = None
38+
39+
40+
@dataclass
41+
class PoseResult:
42+
pose: np.ndarray | None
43+
timestamp: float
44+
packet: PosePacket | None = None

0 commit comments

Comments
 (0)