Visitar URL original
Add internal helper for batched modelzoo inference from in-memory arrays (inference runner) by deruyter92 · Pull Request #3222 · DeepLabCut/DeepLabCut · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add specialcase for humanbody inference
  • Loading branch information
deruyter92 committed Feb 26, 2026
commit f1ef0daf2fd7912724c54ad11877a05703fa8818
79 changes: 70 additions & 9 deletions deeplabcut/pose_estimation_pytorch/modelzoo/inference_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,67 @@
import torch

from deeplabcut.core.config import read_config_as_dict
from deeplabcut.pose_estimation_pytorch.apis.utils import get_inference_runners
from deeplabcut.pose_estimation_pytorch.apis.utils import (
get_filtered_coco_detector_inference_runner,
get_inference_runners,
get_pose_inference_runner,
)
from deeplabcut.pose_estimation_pytorch.modelzoo.utils import (
get_super_animal_snapshot_path,
load_super_animal_config,
update_config,
)
from deeplabcut.pose_estimation_pytorch.runners import InferenceRunner
from deeplabcut.pose_estimation_pytorch.task import Task


def _build_humanbody_inference_runners(
model_cfg: dict,
model_name: str,
detector_name: str | None,
max_individuals: int,
batch_size: int,
detector_batch_size: int,
customized_pose_checkpoint: str | Path | None,
customized_detector_checkpoint: str | Path | None,
) -> tuple[InferenceRunner, InferenceRunner, dict]:
if customized_detector_checkpoint is not None:
logging.warning(
"customized_detector_checkpoint is ignored for superanimal_humanbody. "
"A filtered torchvision detector runner is used instead."
)

torchvision_detector_name = (
detector_name
if detector_name is not None
else "fasterrcnn_mobilenet_v3_large_fpn"
)

pose_snapshot_path = customized_pose_checkpoint
if pose_snapshot_path is None:
pose_snapshot_path = get_super_animal_snapshot_path(
dataset="superanimal_humanbody",
model_name=model_name,
download=True,
)

COCO_PERSON = 1
Comment thread
deruyter92 marked this conversation as resolved.
Resolved
detector_runner = get_filtered_coco_detector_inference_runner(
model_name=torchvision_detector_name,
category_id=COCO_PERSON,
batch_size=detector_batch_size,
max_individuals=max_individuals,
model_config=model_cfg,
)
pose_runner = get_pose_inference_runner(
model_cfg,
snapshot_path=pose_snapshot_path,
batch_size=batch_size,
max_individuals=max_individuals,
)
return pose_runner, detector_runner, model_cfg


def create_superanimal_inference_runners(
superanimal_name: str,
model_name: str,
Expand All @@ -49,8 +101,11 @@ def create_superanimal_inference_runners(
superanimal_name: Name of the SuperAnimal dataset, e.g.
``"superanimal_quadruped"``.
model_name: Pose model architecture name, e.g. ``"hrnet_w32"``.
detector_name: Detector architecture name for top-down inference, e.g.
``"fasterrcnn_resnet50_fpn_v2"``. Can be ``None`` for bottom-up models.
detector_name: Detector architecture name. For top-down SuperAnimal models,
use detector names such as ``"fasterrcnn_resnet50_fpn_v2"``. For
``superanimal_humanbody``, this is interpreted as a torchvision detector
name (default: ``"fasterrcnn_mobilenet_v3_large_fpn"``). Can be ``None``
for bottom-up models.
max_individuals: Maximum number of individuals to keep per frame.
batch_size: Batch size for pose inference.
detector_batch_size: Batch size for detector inference.
Expand Down Expand Up @@ -104,12 +159,6 @@ def create_superanimal_inference_runners(
"FMPose3D is not supported in this helper. Use the FMPose3D inference API."
)

if superanimal_name == "superanimal_humanbody":
raise NotImplementedError(
"superanimal_humanbody is currently not supported by this helper because "
"it relies on modelzoo.build_weight_init, which does not support this dataset."
)

if device in (None, "auto"):
device = "cuda:0" if torch.cuda.is_available() else "cpu"
Comment thread
deruyter92 marked this conversation as resolved.
Resolved

Expand All @@ -125,6 +174,18 @@ def create_superanimal_inference_runners(
detector_name=detector_name,
)

if superanimal_name == "superanimal_humanbody":
return _build_humanbody_inference_runners(
model_cfg=model_cfg,
model_name=model_name,
detector_name=detector_name,
max_individuals=max_individuals,
batch_size=batch_size,
detector_batch_size=detector_batch_size,
customized_pose_checkpoint=customized_pose_checkpoint,
customized_detector_checkpoint=customized_detector_checkpoint,
)

# Top-down models typically need a detector for bbox generation. If no detector
# is configured, the returned detector_runner will be None and callers should
# provide bboxes in the pose input context.
Expand Down