From c7f6655856944a7b26363834afd268b85a249c8a Mon Sep 17 00:00:00 2001 From: Niels Poulsen Date: Tue, 3 Dec 2024 18:05:07 +0100 Subject: [PATCH 1/2] bug fix KeypointAwareCrop: uniform sampling when no keypoints present --- deeplabcut/pose_estimation_pytorch/data/dataset.py | 2 +- deeplabcut/pose_estimation_pytorch/data/transforms.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/deeplabcut/pose_estimation_pytorch/data/dataset.py b/deeplabcut/pose_estimation_pytorch/data/dataset.py index cbb9b9726a..c2e0da9891 100644 --- a/deeplabcut/pose_estimation_pytorch/data/dataset.py +++ b/deeplabcut/pose_estimation_pytorch/data/dataset.py @@ -250,7 +250,7 @@ def _prepare_final_annotation_dict( # we use ..., :3 to pass the visibility flag along return { - "keypoints": pad_to_length(keypoints[..., :3], num_animals, -1).astype( + "keypoints": pad_to_length(keypoints[..., :3], num_animals, 0).astype( np.single ), "keypoints_unique": keypoints_unique[..., :3].astype(np.single), diff --git a/deeplabcut/pose_estimation_pytorch/data/transforms.py b/deeplabcut/pose_estimation_pytorch/data/transforms.py index 6e5bd0d1e9..5aff747e38 100644 --- a/deeplabcut/pose_estimation_pytorch/data/transforms.py +++ b/deeplabcut/pose_estimation_pytorch/data/transforms.py @@ -281,6 +281,8 @@ def get_params_dependent_on_targets(self, params: dict[str, Any]) -> dict[str, A sampling = self.crop_sampling if self.crop_sampling == "hybrid": sampling = np.random.choice(["uniform", "density"]) + if len(kpts) == 0: + sampling = "uniform" if sampling == "uniform": center = np.random.random(2) else: @@ -310,7 +312,7 @@ def apply_to_keypoints( self, keypoints, **params, - ) -> list[float]: + ) -> list[tuple[float]]: keypoints = super().apply_to_keypoints(keypoints, **params) new_keypoints = [] for kp in keypoints: From 1eda615ebb3d71f3ec1210afdd36dfaa8a602c3a Mon Sep 17 00:00:00 2001 From: Niels Poulsen Date: Tue, 3 Dec 2024 18:22:15 +0100 Subject: [PATCH 2/2] symmetric translation px --- deeplabcut/pose_estimation_pytorch/data/transforms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deeplabcut/pose_estimation_pytorch/data/transforms.py b/deeplabcut/pose_estimation_pytorch/data/transforms.py index 5aff747e38..6d14870bd7 100644 --- a/deeplabcut/pose_estimation_pytorch/data/transforms.py +++ b/deeplabcut/pose_estimation_pytorch/data/transforms.py @@ -78,7 +78,7 @@ def build_transforms(augmentations: dict) -> A.BaseCompose: if rotation is not None: rotation = (-rotation, rotation) if translation is not None: - translation = (0, translation) + translation = (-translation, translation) transforms.append( A.Affine(