Visitar URL original
Superanimal humanbody: Use filtered detector by maximpavliv · Pull Request #3066 · DeepLabCut/DeepLabCut · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
2abf37c
Trim superanimal_humanbody.yaml default project config
maximpavliv Jul 21, 2025
a1a6be1
Trim superanimal_humanbody_colors
maximpavliv Jul 21, 2025
dfbce1d
Correct get_checkpoint_epoch
maximpavliv Jul 21, 2025
1432a73
Add rtmpose_x modelzoo model config
maximpavliv Jul 21, 2025
a4d74cc
Add FilteredDetector
maximpavliv Jul 21, 2025
0cbfe59
Add get_filtered_coco_detector_inference_runner() method
maximpavliv Jul 21, 2025
84b230e
Add ScaleToUnitRange transform
maximpavliv Jul 21, 2025
c4c1318
Superanimal humanbody inference: use filtered detector runner
maximpavliv Jul 21, 2025
dc511cd
ModelZoo tab: make humanbody general case
maximpavliv Jul 21, 2025
479cc66
get_super_animal_scorer(): add torchvision_detector_name arg
maximpavliv Jul 21, 2025
6a14584
Remove superanimal_humanbody_video_inference.py module
maximpavliv Jul 21, 2025
6774812
Regularize get_super_animal_model_config_path()
maximpavliv Jul 21, 2025
424ac92
Regularize load_super_animal_config()
maximpavliv Jul 21, 2025
04438f8
Regularize download_super_animal_snapshot()
maximpavliv Jul 21, 2025
256977b
update_config(): superanimal_humanbody - compatible
maximpavliv Jul 21, 2025
8d4cf20
Revert video_inference()
maximpavliv Jul 21, 2025
edf4f9d
Revert create_df_from_prediction()
maximpavliv Jul 21, 2025
cded581
Restore CTDInferenceRunner
maximpavliv Jul 21, 2025
7eaf923
Remove TorchvisionDetectorInferenceRunner
maximpavliv Jul 21, 2025
feb34d1
Revert DetectorInferenceRunner
maximpavliv Jul 21, 2025
711a47e
superanimal_analyze_images() - make humanbody compatible
maximpavliv Jul 21, 2025
28e4dd0
Revert build_predictions_dataframe()
maximpavliv Jul 21, 2025
193f935
Revert get_inference_runners()
maximpavliv Jul 21, 2025
613b2ac
Revert detectors/fasterRCNN.py
maximpavliv Jul 21, 2025
d848741
Revert detectors/torchvision.py
maximpavliv Jul 21, 2025
bba8689
Revert base Runner
maximpavliv Jul 21, 2025
25fa08d
Fix superanimal_humanbody unit test
maximpavliv Jul 31, 2025
425484b
Disable video adaptation for superanimal_humanbody
maximpavliv Jul 31, 2025
4b04013
Fix testscript_superanimal_inference.py
maximpavliv Jul 31, 2025
eea470e
Remove debug print
maximpavliv Jul 31, 2025
3d47a36
Black formatting
maximpavliv Jul 31, 2025
5aeafda
Merge branch 'main' into maxim/superanimal_humanbody_filtered_detector
MMathisLab Aug 24, 2025
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
Remove TorchvisionDetectorInferenceRunner
  • Loading branch information
maximpavliv committed Jul 21, 2025
commit 7eaf923a015384ae895e4404ad766a8e90e68309
1 change: 0 additions & 1 deletion deeplabcut/pose_estimation_pytorch/runners/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from deeplabcut.pose_estimation_pytorch.runners.inference import (
build_inference_runner,
DetectorInferenceRunner,
TorchvisionDetectorInferenceRunner,
InferenceRunner,
PoseInferenceRunner,
)
Expand Down
71 changes: 1 addition & 70 deletions deeplabcut/pose_estimation_pytorch/runners/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import numpy as np
import torch
import torch.nn as nn
import torchvision

import deeplabcut.pose_estimation_pytorch.post_processing.nms as nms
import deeplabcut.pose_estimation_pytorch.runners.ctd as ctd
Expand Down Expand Up @@ -889,69 +888,7 @@ def inference(self, images) -> list[dict[str, np.ndarray]]:
return super().inference(images)


class TorchvisionDetectorInferenceRunner(DetectorInferenceRunner):
"""Runner for torchvision detector inference that bypasses standard preprocessing"""

def __init__(self, model: BaseDetector, **kwargs):
"""
Args:
model: The torchvision detector to use for inference.
**kwargs: Inference runner kwargs.
"""
super().__init__(model, **kwargs)

def predict(
self, inputs: torch.Tensor, **kwargs
) -> list[dict[str, dict[str, np.ndarray]]]:
"""Makes predictions from a model input and output

Args:
inputs: the inputs to the model, of shape (batch_size, ...)

Returns:
predictions for each of the 'batch_size' inputs, made by each head
"""
if self.device and "cuda" in str(self.device):
with torch.autocast(device_type=str(self.device)):
_, raw_predictions = self.model(inputs.to(self.device))
else:
_, raw_predictions = self.model(inputs.to(self.device))

predictions = []
for item in raw_predictions:
if isinstance(item, dict) and "boxes" in item:
predictions.append({
"detection": {
"bboxes": item["boxes"].cpu().numpy().reshape(-1, 4),
"bbox_scores": item["scores"].cpu().numpy().reshape(-1),
}
})
else:
# Handle unexpected output format
predictions.append({
"detection": {
"bboxes": np.zeros((0, 4)),
"bbox_scores": np.zeros(0),
}
})

return predictions

def inference(self, images) -> list[dict[str, np.ndarray]]:
"""Run inference using the torchvision detector's inference method

Args:
images: List of image paths, PIL Images, or numpy arrays

Returns:
List of detection results with bboxes in xywh format
"""
# Always use the detector's own inference method for torchvision detectors
if hasattr(self.model, 'inference'):
return self.model.inference(images)
else:
# This should never happen for torchvision detectors
raise RuntimeError("TorchvisionDetectorInferenceRunner requires model to have inference method")


def build_inference_runner(
Expand Down Expand Up @@ -1019,13 +956,7 @@ def build_inference_runner(
f"The DynamicCropper can only be used for pose estimation; not object "
f"detection. Please turn off dynamic cropping."
)

# Simple check: if superanimal_humanbody, use torchvision inference
# Otherwise, use standard inference
if hasattr(model, 'superanimal_name') and model.superanimal_name == "superanimal_humanbody":
return TorchvisionDetectorInferenceRunner(**kwargs)
else:
return DetectorInferenceRunner(**kwargs)
return DetectorInferenceRunner(**kwargs)

if task != Task.BOTTOM_UP:
if dynamic is not None and not isinstance(dynamic, TopDownDynamicCropper):
Expand Down