Skip to content

Commit 11690ed

Browse files
committed
Minor refactors (comments, unused imports, unused variables)
1 parent 7e9b4b4 commit 11690ed

10 files changed

Lines changed: 20 additions & 31 deletions

File tree

dlclive/benchmark.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -653,26 +653,26 @@ def _get_metadata(
653653
):
654654
try:
655655
fourcc = decode_fourcc(cap.get(cv2.CAP_PROP_FOURCC))
656-
except:
656+
except Exception:
657657
fourcc = ""
658658
try:
659659
fps = round(cap.get(cv2.CAP_PROP_FPS))
660-
except:
660+
except Exception:
661661
fps = None
662662
try:
663663
pix_fmt = decode_fourcc(cap.get(cv2.CAP_PROP_CODEC_PIXEL_FORMAT))
664-
except:
664+
except Exception:
665665
pix_fmt = ""
666666
try:
667667
frame_count = round(cap.get(cv2.CAP_PROP_FRAME_COUNT))
668-
except:
668+
except Exception:
669669
frame_count = None
670670
try:
671671
orig_im_size = (
672672
round(cap.get(cv2.CAP_PROP_FRAME_WIDTH)),
673673
round(cap.get(cv2.CAP_PROP_FRAME_HEIGHT)),
674674
)
675-
except:
675+
except Exception:
676676
orig_im_size = None
677677

678678
meta = {

dlclive/check_install/check_install.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,15 @@
55
Licensed under GNU Lesser General Public License v3.0
66
"""
77

8-
import os
9-
import urllib.request
108
import argparse
119
import shutil
12-
13-
import urllib.request
1410
import warnings
1511
from pathlib import Path
1612

17-
from dlclive.utils import download_file
1813
from dlclibrary.dlcmodelzoo.modelzoo_download import download_huggingface_model
1914

2015
import dlclive
16+
from dlclive.utils import download_file
2117
from dlclive.benchmark import benchmark_videos
2218
from dlclive.engine import Engine
2319

dlclive/core/inferenceutils.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def __contains__(self, assembly):
103103

104104
def __add__(self, other):
105105
if other in self:
106-
raise ValueError("Assemblies contain shared joints.")
106+
raise ArithmeticError("Assemblies contain shared joints.")
107107

108108
assembly = Assembly(self.data.shape[0])
109109
for link in self._links + other._links:
@@ -340,6 +340,7 @@ def calibrate(self, train_data_file):
340340
try:
341341
df.drop("single", level="individuals", axis=1, inplace=True)
342342
except KeyError:
343+
# The "single" individual column may be absent in some training datasets; ignore if missing.
343344
pass
344345
n_bpts = len(df.columns.get_level_values("bodyparts").unique())
345346
if n_bpts == 1:
@@ -547,11 +548,9 @@ def push_to_stack(i):
547548
d = self.calc_assembly_mahalanobis_dist(assembly, nan_policy=nan_policy)
548549
if d < d_old:
549550
push_to_stack(new_ind)
550-
try:
551-
_, _, link = heapq.heappop(tabu)
552-
heapq.heappush(stack, (-link.affinity, next(counter), link))
553-
except IndexError:
554-
pass
551+
if tabu:
552+
_, _, link = heapq.heappop(tabu)
553+
heapq.heappush(stack, (-link.affinity, next(counter), link))
555554
else:
556555
heapq.heappush(tabu, (d - d_old, next(counter), best))
557556
assembly.__dict__.update(assembly._dict)
@@ -597,8 +596,8 @@ def build_assemblies(self, links):
597596
self._fill_assembly(
598597
assembly, lookup, assembled, self.safe_edge, self.nan_policy
599598
)
600-
for link in assembly._links:
601-
i, j = link.idx
599+
for assembly_link in assembly._links:
600+
i, j = assembly_link.idx
602601
lookup[i].pop(j)
603602
lookup[j].pop(i)
604603
assembled.update(assembly._idx)
@@ -666,6 +665,8 @@ def build_assemblies(self, links):
666665
for idx in store[j]._idx:
667666
store[idx] = store[i]
668667
except KeyError:
668+
# Some links may reference indices that were never added to `store`;
669+
# in that case we intentionally skip merging for this link
669670
pass
670671

671672
# Second pass without edge safety
@@ -1086,6 +1087,7 @@ def parse_ground_truth_data_file(h5_file):
10861087
try:
10871088
df.drop("single", axis=1, level="individuals", inplace=True)
10881089
except KeyError:
1090+
# Ignore if the "single" individual column is absent
10891091
pass
10901092
# Cast columns of dtype 'object' to float to avoid TypeError
10911093
# further down in _parse_ground_truth_data.

dlclive/pose_estimation_pytorch/models/detectors/base.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#
1111
from __future__ import annotations
1212

13-
import logging
1413
from abc import ABC, abstractmethod
1514

1615
import torch

dlclive/pose_estimation_pytorch/models/heads/dlcrnet.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ def forward(self, x: torch.Tensor) -> dict[str, torch.Tensor]:
114114
features = self.convt4(x)
115115
stage2_in = torch.cat((stage1_hm_out, stage1_paf_out, features), dim=1)
116116
stage_in = stage2_in
117-
stage_paf_out = stage1_paf_out
118117
stage_hm_out = stage1_hm_out
119118
for i, (hm_ref_layer, paf_ref_layer) in enumerate(
120119
zip(self.hm_ref_layers, self.paf_ref_layers)

dlclive/pose_estimation_pytorch/models/necks/layers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
import torch
1313
import torch.nn.functional as F
14-
from einops import rearrange, repeat
14+
from einops import rearrange
1515

1616

1717
class Residual(torch.nn.Module):

dlclive/pose_estimation_pytorch/models/necks/transformer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ def _make_position_embedding(
171171
with torch.no_grad():
172172
self.pe_h = h
173173
self.pe_w = w
174-
length = h * w
175174
if pe_type != "learnable":
176175
self.pos_embedding = torch.nn.Parameter(
177176
make_sine_position_embedding(h, w, d_model), requires_grad=False

dlclive/pose_estimation_pytorch/models/predictors/dekr_predictor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def max_pool(self, heatmap: torch.Tensor) -> torch.Tensor:
263263
# Assuming you have 'heatmap' tensor
264264
max_pooled_heatmap = predictor.max_pool(heatmap)
265265
"""
266-
pool1 = torch.nn.MaxPool2d(3, 1, 1)
266+
pool1 = torch.nn.MaxPool2d(3, 1, 1) # TODO JR 01/2026: Are these unused variables informative?
267267
pool2 = torch.nn.MaxPool2d(5, 1, 2)
268268
pool3 = torch.nn.MaxPool2d(7, 1, 3)
269269
map_size = (heatmap.shape[1] + heatmap.shape[2]) / 2.0

dlclive/pose_estimation_tensorflow/graph.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
vers = (tf.__version__).split(".")
1212
if int(vers[0]) == 2 or int(vers[0]) == 1 and int(vers[1]) > 12:
1313
tf = tf.compat.v1
14-
else:
15-
tf = tf
1614

1715

1816
def read_graph(file):

tests/test_benchmark_script.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
import os
21
import glob
3-
import pathlib
42
import pytest
53
from dlclive import benchmark_videos, download_benchmarking_data
64
from dlclive.engine import Engine
@@ -23,26 +21,24 @@ def test_benchmark_script_runs(tmp_path):
2321

2422
for model_path in dog_models:
2523
print(f"Running dog model: {model_path}")
26-
result = benchmark_videos(
24+
benchmark_videos(
2725
model_path=model_path,
2826
model_type="base" if Engine.from_model_path(model_path) == Engine.TENSORFLOW else "pytorch",
2927
video_path=dog_video,
3028
output=str(out_dir),
3129
n_frames=n_frames,
3230
pixels=pixels
3331
)
34-
print("Dog model result:", result)
3532

3633
for model_path in mouse_models:
3734
print(f"Running mouse model: {model_path}")
38-
result = benchmark_videos(
35+
benchmark_videos(
3936
model_path=model_path,
4037
model_type="base" if Engine.from_model_path(model_path) == Engine.TENSORFLOW else "pytorch",
4138
video_path=mouse_video,
4239
output=str(out_dir),
4340
n_frames=n_frames,
4441
pixels=pixels
4542
)
46-
print("Mouse model result:", result)
4743

4844
assert any(out_dir.iterdir())

0 commit comments

Comments
 (0)