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
Show file tree
Hide file tree
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
centralize constant COCO_PERSON_CATEGORY_ID.
Instead of several definitions of the persons class in the coco dataset, a single constant is placed in modelzoo.utils. This reduces code duplication improves maintainability and promotes centralized logic, rather than implying that the argument is intented to be tuned by the callers.
  • Loading branch information
deruyter92 committed Mar 12, 2026
commit fc4a67c43d3f40bc80158e2070259ccada901b83
8 changes: 5 additions & 3 deletions deeplabcut/pose_estimation_pytorch/apis/analyze_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@
get_filtered_coco_detector_inference_runner,
)
from deeplabcut.pose_estimation_pytorch.data.ctd import CondFromModel
from deeplabcut.pose_estimation_pytorch.modelzoo.utils import update_config
from deeplabcut.pose_estimation_pytorch.modelzoo.utils import (
COCO_PERSON_CATEGORY_ID,
update_config,
)
from deeplabcut.pose_estimation_pytorch.task import Task
from deeplabcut.pose_estimation_pytorch.utils import resolve_device
from deeplabcut.utils import auxfun_videos, auxiliaryfunctions
Expand Down Expand Up @@ -176,10 +179,9 @@ def superanimal_analyze_images(
torchvision_detector_name = detector_name
else:
torchvision_detector_name = "fasterrcnn_mobilenet_v3_large_fpn"
COCO_PERSON = 1 # COCO class ID for person
filtered_detector_config = {
"torchvision_detector_name": torchvision_detector_name,
"category_id": COCO_PERSON,
"category_id": COCO_PERSON_CATEGORY_ID,
}

if customized_model_config is None:
Expand Down
4 changes: 2 additions & 2 deletions deeplabcut/pose_estimation_pytorch/modelzoo/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
get_filtered_coco_detector_inference_runner,
)
from deeplabcut.pose_estimation_pytorch.modelzoo.utils import (
COCO_PERSON_CATEGORY_ID,
raise_warning_if_called_directly,
)
from deeplabcut.utils.make_labeled_video import create_video
Expand Down Expand Up @@ -110,10 +111,9 @@ def _video_inference_superanimal(
if superanimal_name == "superanimal_humanbody":
if not torchvision_detector_name:
torchvision_detector_name = "fasterrcnn_mobilenet_v3_large_fpn"
COCO_PERSON = 1 # COCO class ID for person
detector_runner = get_filtered_coco_detector_inference_runner(
model_name=torchvision_detector_name,
category_id=COCO_PERSON,
category_id=COCO_PERSON_CATEGORY_ID,
batch_size=detector_batch_size,
max_individuals=max_individuals,
model_config=model_cfg,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
get_pose_inference_runner,
)
from deeplabcut.pose_estimation_pytorch.modelzoo.utils import (
COCO_PERSON_CATEGORY_ID,
get_super_animal_snapshot_path,
load_super_animal_config,
update_config,
Expand Down Expand Up @@ -63,10 +64,9 @@ def _build_humanbody_inference_runners(
download=True,
)

COCO_PERSON = 1
detector_runner = get_filtered_coco_detector_inference_runner(
model_name=torchvision_detector_name,
category_id=COCO_PERSON,
category_id=COCO_PERSON_CATEGORY_ID,
batch_size=detector_batch_size,
max_individuals=max_individuals,
model_config=model_cfg,
Expand Down
3 changes: 3 additions & 0 deletions deeplabcut/pose_estimation_pytorch/modelzoo/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
from deeplabcut.pose_estimation_pytorch.config.make_pose_config import add_metadata
from deeplabcut.utils import auxiliaryfunctions

# COCO category ID for the "person" class.
COCO_PERSON_CATEGORY_ID = 1


def get_model_configs_folder_path() -> Path:
"""Returns: the folder containing the SuperAnimal model configuration files"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
FilteredDetector,
)
from deeplabcut.pose_estimation_pytorch.modelzoo import load_super_animal_config
from deeplabcut.pose_estimation_pytorch.modelzoo.utils import COCO_PERSON_CATEGORY_ID


def test_torchvision_detector():
Expand All @@ -34,14 +35,15 @@ def test_torchvision_detector():
print("Torchvision detector loaded successfully!")

# Test loading the FilteredDetector
COCO_PERSON = 1 # COCO class ID for person
person_detector = FilteredDetector(coco_detector, class_id=COCO_PERSON)
person_detector = FilteredDetector(
coco_detector, class_id=COCO_PERSON_CATEGORY_ID
)
person_detector.eval()
print("Filtered detector loaded successfully!")

_ = get_filtered_coco_detector_inference_runner(
model_name=detector_name,
category_id=COCO_PERSON,
category_id=COCO_PERSON_CATEGORY_ID,
batch_size=1,
model_config=superanimal_config,
)
Expand Down
Loading