Skip to content

Commit aa53622

Browse files
committed
Update CI workflow and add duplication note to dynamic_cropping.py
Removed the --no-cache flag from 'uv sync' in the testing workflow, enhanced pytest coverage reporting, and added a step to summarize coverage in the GitHub Actions job summary. Added a note in dynamic_cropping.py about duplication with another file and referenced existing tests.
1 parent 131fdef commit aa53622

2 files changed

Lines changed: 27 additions & 27 deletions

File tree

.github/workflows/testing.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
python-version: ${{ matrix.python-version }}
5454

5555
- name: Install the project
56-
run: uv sync --no-cache --all-extras --dev
56+
run: uv sync --all-extras --dev
5757
shell: bash
5858

5959
- name: Install ffmpeg
@@ -72,9 +72,20 @@ jobs:
7272
run: uv run dlc-live-test --nodisplay
7373

7474
- name: Run DLC Live Unit Tests
75-
run: uv run pytest --cov=dlclive --cov-report=xml
75+
run: uv run pytest --cov=dlclive --cov-report=xml --cov-report=term-missing
7676

7777
- name: Coverage Report
7878
uses: codecov/codecov-action@v5
7979
with:
8080
files: ./coverage.xml
81+
flags: ${{ matrix.os }}-py${{ matrix.python-version }}
82+
name: codecov-${{ matrix.os }}-py${{ matrix.python-version }}
83+
- name: Add coverage to job summary
84+
if: always()
85+
shell: bash
86+
run: |
87+
uv run python -m coverage report -m > coverage.txt
88+
echo "## Coverage (dlclive)" >> "$GITHUB_STEP_SUMMARY"
89+
echo '```' >> "$GITHUB_STEP_SUMMARY"
90+
cat coverage.txt >> "$GITHUB_STEP_SUMMARY"
91+
echo '```' >> "$GITHUB_STEP_SUMMARY"

dlclive/pose_estimation_pytorch/dynamic_cropping.py

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@
77
# https://github.com/DeepLabCut/DeepLabCut/blob/main/AUTHORS
88
#
99
# Licensed under GNU Lesser General Public License v3.0
10-
#
10+
11+
# NOTE DUPLICATED @C-Achard 2026-26-01: Duplication between this file
12+
# and deeplabcut/pose_estimation_pytorch/runners/dynamic_cropping.py
13+
# NOTE Testing already exists at deeplabcut/tests/pose_estimation_pytorch/runners/test_dynamic_cropper.py
1114
"""Modules to dynamically crop individuals out of videos to improve video analysis"""
15+
1216
from __future__ import annotations
1317

1418
import math
1519
from dataclasses import dataclass, field
16-
from typing import Optional
1720

1821
import torch
1922
import torchvision.transforms.functional as F
@@ -79,10 +82,7 @@ def crop(self, image: torch.Tensor) -> torch.Tensor:
7982
height.
8083
"""
8184
if len(image) != 1:
82-
raise RuntimeError(
83-
"DynamicCropper can only be used with batch size 1 (found image "
84-
f"shape: {image.shape})"
85-
)
85+
raise RuntimeError(f"DynamicCropper can only be used with batch size 1 (found image shape: {image.shape})")
8686

8787
if self._shape is None:
8888
self._shape = image.shape[3], image.shape[2]
@@ -114,7 +114,7 @@ def update(self, pose: torch.Tensor) -> torch.Tensor:
114114
The pose, with coordinates updated to the full image space.
115115
"""
116116
if self._shape is None:
117-
raise RuntimeError(f"You must call `crop` before calling `update`.")
117+
raise RuntimeError("You must call `crop` before calling `update`.")
118118

119119
# offset the pose to the original image space
120120
offset_x, offset_y = 0, 0
@@ -153,9 +153,7 @@ def reset(self) -> None:
153153
self._crop = None
154154

155155
@staticmethod
156-
def build(
157-
dynamic: bool, threshold: float, margin: int
158-
) -> Optional["DynamicCropper"]:
156+
def build(dynamic: bool, threshold: float, margin: int) -> DynamicCropper | None:
159157
"""Builds the DynamicCropper based on the given parameters
160158
161159
Args:
@@ -309,10 +307,7 @@ def crop(self, image: torch.Tensor) -> torch.Tensor:
309307
`crop` was previously called with an image of a different W or H.
310308
"""
311309
if len(image) != 1:
312-
raise RuntimeError(
313-
"DynamicCropper can only be used with batch size 1 (found image "
314-
f"shape: {image.shape})"
315-
)
310+
raise RuntimeError(f"DynamicCropper can only be used with batch size 1 (found image shape: {image.shape})")
316311

317312
if self._shape is None:
318313
self._shape = image.shape[3], image.shape[2]
@@ -349,7 +344,7 @@ def update(self, pose: torch.Tensor) -> torch.Tensor:
349344
The pose, with coordinates updated to the full image space.
350345
"""
351346
if self._shape is None:
352-
raise RuntimeError(f"You must call `crop` before calling `update`.")
347+
raise RuntimeError("You must call `crop` before calling `update`.")
353348

354349
# check whether this was a patched crop
355350
batch_size = pose.shape[0]
@@ -399,9 +394,7 @@ def update(self, pose: torch.Tensor) -> torch.Tensor:
399394

400395
return pose
401396

402-
def _prepare_bounding_box(
403-
self, x1: int, y1: int, x2: int, y2: int
404-
) -> tuple[int, int, int, int]:
397+
def _prepare_bounding_box(self, x1: int, y1: int, x2: int, y2: int) -> tuple[int, int, int, int]:
405398
"""Prepares the bounding box for cropping.
406399
407400
Adds a margin around the bounding box, then transforms it into the target aspect
@@ -498,12 +491,8 @@ def generate_patches(self) -> list[tuple[int, int, int, int]]:
498491
Returns:
499492
A list of patch coordinates as tuples (x0, y0, x1, y1).
500493
"""
501-
patch_xs = self.split_array(
502-
self._shape[0], self._patch_counts[0], self._patch_overlap
503-
)
504-
patch_ys = self.split_array(
505-
self._shape[1], self._patch_counts[1], self._patch_overlap
506-
)
494+
patch_xs = self.split_array(self._shape[0], self._patch_counts[0], self._patch_overlap)
495+
patch_ys = self.split_array(self._shape[1], self._patch_counts[1], self._patch_overlap)
507496

508497
patches = []
509498
for y0, y1 in patch_ys:
@@ -534,7 +523,7 @@ def split_array(size: int, n: int, overlap: int) -> list[tuple[int, int]]:
534523
segment_size = (padded_size // n) + (padded_size % n > 0)
535524
segments = []
536525
end = overlap
537-
for i in range(n):
526+
for _i in range(n):
538527
start = end - overlap
539528
end = start + segment_size
540529
if end > size:

0 commit comments

Comments
 (0)