Visitar URL original
Fix Faster R-CNN detector inference crashing on box_score_thresh: null by rysk-t · Pull Request #3470 · 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
Normalize detector box score threshold
Set a consistent default for `box_score_thresh` and normalize `None` values before model construction. `DetectorModelConfig` now defaults to `0.01` and uses a validator to translate `null` config values to that default, while the torchvision detector adaptor reuses the shared constant instead of hardcoded literals. This prevents Faster R-CNN inference crashes caused by `None` threshold comparisons.
  • Loading branch information
C-Achard committed Aug 31, 2026
commit 6db842dbaa4f5497aa18e864cebe041aa334a61e
11 changes: 9 additions & 2 deletions deeplabcut/pose_estimation_pytorch/config/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
#
"""Model configuration class for DeepLabCut pose estimation models."""

from pydantic import Field
from pydantic import Field, field_validator

from deeplabcut.core.config import DLCBaseConfig
from deeplabcut.core.config.validation import Fraction

DEFAULT_BOX_SCORE_THRESH = 0.01


class ModelConfig(DLCBaseConfig):
"""Complete model configuration.
Expand Down Expand Up @@ -48,4 +50,9 @@ class DetectorModelConfig(DLCBaseConfig):
freeze_bn_stats: bool = False
freeze_bn_weights: bool = False
variant: str | None = None
box_score_thresh: Fraction | None = None
box_score_thresh: Fraction | None = DEFAULT_BOX_SCORE_THRESH

@field_validator("box_score_thresh", mode="before")
@classmethod
def normalize_box_score_thresh(cls, v):
return DEFAULT_BOX_SCORE_THRESH if v is None else v
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import torch
import torchvision.models.detection as detection

from deeplabcut.pose_estimation_pytorch.config.pose import DEFAULT_BOX_SCORE_THRESH
from deeplabcut.pose_estimation_pytorch.models.detectors.base import (
BaseDetector,
)
Expand Down Expand Up @@ -58,7 +59,7 @@ def __init__(
num_classes: int | None = 2,
freeze_bn_stats: bool = False,
freeze_bn_weights: bool = False,
box_score_thresh: float | None = 0.01,
box_score_thresh: float | None = DEFAULT_BOX_SCORE_THRESH,
model_kwargs: dict | None = None,
) -> None:
super().__init__(
Expand All @@ -71,7 +72,7 @@ def __init__(
# Generated configs store ``box_score_thresh: null`` meaning "use
# the default"; torchvision's Faster R-CNN would keep the None and
# crash when comparing scores against it during inference.
box_score_thresh = 0.01
box_score_thresh = DEFAULT_BOX_SCORE_THRESH

# Load the model
model_fn = getattr(detection, model)
Expand Down