-
Notifications
You must be signed in to change notification settings - Fork 54
Jaap/fix no detections case #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dlclive3
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,7 @@ | |||||||||||
| from dataclasses import dataclass | ||||||||||||
| from pathlib import Path | ||||||||||||
| from typing import Literal | ||||||||||||
| import warnings | ||||||||||||
|
|
||||||||||||
| import numpy as np | ||||||||||||
| import torch | ||||||||||||
|
|
@@ -131,15 +132,25 @@ def __init__( | |||||||||||
| path: str | Path, | ||||||||||||
| device: str = "auto", | ||||||||||||
| precision: Literal["FP16", "FP32"] = "FP32", | ||||||||||||
| single_animal: bool = True, | ||||||||||||
| single_animal: bool | None = None, | ||||||||||||
| dynamic: dict | dynamic_cropping.DynamicCropper | None = None, | ||||||||||||
| top_down_config: dict | TopDownConfig | None = None, | ||||||||||||
| ) -> None: | ||||||||||||
| super().__init__(path) | ||||||||||||
| self.device = _parse_device(device) | ||||||||||||
| self.precision = precision | ||||||||||||
| if single_animal is not None: | ||||||||||||
| warnings.warn( | ||||||||||||
| "The `single_animal` parameter is deprecated and will be removed " | ||||||||||||
| "in a future version. The number of individuals will be automatically inferred " | ||||||||||||
| "from the model configuration. Remove argument `single_animal` or set " | ||||||||||||
| "`single_animal=None` to accept the inferred value and silence this warning.", | ||||||||||||
| DeprecationWarning, | ||||||||||||
| stacklevel=2, | ||||||||||||
| ) | ||||||||||||
| self.single_animal = single_animal | ||||||||||||
|
|
||||||||||||
| self.n_individuals = None | ||||||||||||
| self.n_bodyparts = None | ||||||||||||
| self.cfg = None | ||||||||||||
| self.detector = None | ||||||||||||
| self.model = None | ||||||||||||
|
|
@@ -191,9 +202,14 @@ def get_pose(self, frame: np.ndarray) -> np.ndarray: | |||||||||||
|
|
||||||||||||
| frame_batch, offsets_and_scales = self._prepare_top_down(tensor, detections) | ||||||||||||
| if len(frame_batch) == 0: | ||||||||||||
| offsets_and_scales = [(0, 0), 1] | ||||||||||||
| else: | ||||||||||||
| tensor = frame_batch # still CHW, batched | ||||||||||||
| zero_pose = ( | ||||||||||||
| np.zeros((self.n_bodyparts, 3)) | ||||||||||||
| if self.n_individuals < 2 else | ||||||||||||
| np.zeros((self.n_individuals, self.n_bodyparts, 3)) | ||||||||||||
| ) | ||||||||||||
|
||||||||||||
| ) | |
| ) | |
| if self.top_down_config.skip_frames is not None: | |
| zero_pose_tensor = torch.from_numpy(zero_pose).to(self.device) | |
| self.top_down_config.skip_frames.update(zero_pose_tensor, w, h) |
Copilot
AI
Jan 13, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If get_pose is called before load_model is called, and the model has a detector with no detections, this will fail with a TypeError when comparing self.n_individuals (which is None) with 2. While calling get_pose before load_model is already a misuse of the API, the error message could be improved. Consider adding a check that self.n_individuals and self.n_bodyparts are not None, or document that load_model must be called first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The early return uses
self.n_individuals < 2to determine the output shape, while the regular path usesself.single_animalat line 240. These two conditions could differ if a user explicitly setssingle_animalto a value that doesn't match the model configuration. For consistency, both code paths should use the same condition (either both useself.single_animalor both useself.n_individuals < 2).