Skip to content

Commit 92fc406

Browse files
committed
Update code duplication marker
1 parent 7ec008f commit 92fc406

5 files changed

Lines changed: 38 additions & 47 deletions

File tree

dlclive/core/inferenceutils.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
#
1111

1212

13-
# NOTE DUPLICATED from deeplabcut/core/inferenceutils.py
13+
# NOTE - DUPLICATED @C-Achard 2026-26-01: Copied from the original DeepLabCut codebase
14+
# from deeplabcut/core/inferenceutils.py
1415
from __future__ import annotations
1516

1617
import heapq

dlclive/modelzoo/resolve_config.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""
2-
Helper function to deal with default values in the model configuration.
2+
Helper function to deal with default values in the model configuration.
33
For instance, "num_bodyparts x 2" is replaced with the number of bodyparts multiplied by 2.
44
"""
5-
# NOTE JR 2026-23-01: This is duplicate code, copied from the original DeepLabCut-Live codebase.
65

6+
# NOTE - DUPLICATED @deruyter92 2026-23-01: Copied from the original DeepLabCut codebase
7+
# from deeplabcut/pose_estimation_pytorch/modelzoo/utils.py
78
import copy
89

910

@@ -78,8 +79,7 @@ def get_updated_value(variable: str) -> int | list[int]:
7879
var_name = var_parts[0]
7980
if updated_values[var_name] is None:
8081
raise ValueError(
81-
f"Found {variable} in the configuration file, but there is no default "
82-
f"value for this variable."
82+
f"Found {variable} in the configuration file, but there is no default value for this variable."
8383
)
8484

8585
if len(var_parts) == 1:
@@ -99,9 +99,7 @@ def get_updated_value(variable: str) -> int | list[int]:
9999
else:
100100
raise ValueError(f"Unknown operator for variable: {variable}")
101101

102-
raise ValueError(
103-
f"Found {variable} in the configuration file, but cannot parse it."
104-
)
102+
raise ValueError(f"Found {variable} in the configuration file, but cannot parse it.")
105103

106104
updated_values = {
107105
"num_bodyparts": num_bodyparts,
@@ -127,10 +125,7 @@ def get_updated_value(variable: str) -> int | list[int]:
127125
backbone_output_channels,
128126
**kwargs,
129127
)
130-
elif (
131-
isinstance(config[k], str)
132-
and config[k].strip().split(" ")[0] in updated_values.keys()
133-
):
128+
elif isinstance(config[k], str) and config[k].strip().split(" ")[0] in updated_values.keys():
134129
config[k] = get_updated_value(config[k])
135130

136-
return config
131+
return config

dlclive/modelzoo/utils.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,53 @@
55
# This should be removed once a solution is found to address duplicate code.
66

77
import copy
8-
from pathlib import Path
98
import logging
9+
from pathlib import Path
1010

11+
from dlclibrary.dlcmodelzoo.modelzoo_download import download_huggingface_model
1112
from ruamel.yaml import YAML
1213

13-
from dlclibrary.dlcmodelzoo.modelzoo_download import download_huggingface_model
1414
from dlclive.modelzoo.resolve_config import update_config
1515

16-
_MODELZOO_PATH = Path(__file__).parent
16+
_MODELZOO_PATH = Path(__file__).parent
1717

1818

1919
def get_super_animal_model_config_path(model_name: str) -> Path:
2020
"""Get the path to the model configuration file for a model and validate choice of model"""
21-
cfg_path = _MODELZOO_PATH / 'model_configs' / f"{model_name}.yaml"
21+
cfg_path = _MODELZOO_PATH / "model_configs" / f"{model_name}.yaml"
2222
if not cfg_path.exists():
2323
raise FileNotFoundError(
24-
f"Modelzoo model configuration file not found: {cfg_path} "
25-
f"Available models: {list_available_models()}"
24+
f"Modelzoo model configuration file not found: {cfg_path} Available models: {list_available_models()}"
2625
)
2726
return cfg_path
2827

2928

3029
def get_super_animal_project_config_path(super_animal: str) -> Path:
3130
"""Get the path to the project configuration file for a project and validate choice of project"""
32-
cfg_path = _MODELZOO_PATH / 'project_configs' / f"{super_animal}.yaml"
31+
cfg_path = _MODELZOO_PATH / "project_configs" / f"{super_animal}.yaml"
3332
if not cfg_path.exists():
3433
raise FileNotFoundError(
35-
f"Modelzoo project configuration file not found: {cfg_path}"
36-
f"Available projects: {list_available_projects()}"
34+
f"Modelzoo project configuration file not found: {cfg_path}Available projects: {list_available_projects()}"
3735
)
3836
return cfg_path
3937

4038

4139
def get_snapshot_folder_path() -> Path:
42-
return _MODELZOO_PATH / 'snapshots'
40+
return _MODELZOO_PATH / "snapshots"
4341

4442

4543
def list_available_models() -> list[str]:
46-
return [p.stem for p in _MODELZOO_PATH.glob('model_configs/*.yaml')]
44+
return [p.stem for p in _MODELZOO_PATH.glob("model_configs/*.yaml")]
4745

4846

4947
def list_available_projects() -> list[str]:
50-
return [p.stem for p in _MODELZOO_PATH.glob('project_configs/*.yaml')]
48+
return [p.stem for p in _MODELZOO_PATH.glob("project_configs/*.yaml")]
5149

5250

5351
def list_available_combinations() -> list[str]:
5452
models = list_available_models()
5553
projects = list_available_projects()
56-
combinations = ['_'.join([p, m]) for p in projects for m in models]
54+
combinations = ["_".join([p, m]) for p in projects for m in models]
5755
return combinations
5856

5957

@@ -65,14 +63,18 @@ def read_config_as_dict(config_path: str | Path) -> dict:
6563
Returns:
6664
The configuration file with pure Python classes
6765
"""
68-
with open(config_path, "r") as f:
69-
cfg = YAML(typ='safe', pure=True).load(f)
66+
with open(config_path) as f:
67+
cfg = YAML(typ="safe", pure=True).load(f)
7068

7169
return cfg
7270

7371

74-
# NOTE JR 2026-23-01: This is duplicate code, copied from the original DeepLabCut-Live codebase.
75-
def add_metadata(project_config: dict, config: dict,) -> dict:
72+
# NOTE - DUPLICATED @deruyter92 2026-23-01: Copied from the original DeepLabCut codebase
73+
# from deeplabcut/pose_estimation_pytorch/config/make_pose_config.py
74+
def add_metadata(
75+
project_config: dict,
76+
config: dict,
77+
) -> dict:
7678
"""Adds metadata to a pytorch pose configuration
7779
7880
Args:
@@ -95,7 +97,8 @@ def add_metadata(project_config: dict, config: dict,) -> dict:
9597
return config
9698

9799

98-
# NOTE JR 2026-23-01: This is duplicate code, copied from the original DeepLabCut-Live codebase.
100+
# NOTE - DUPLICATED @deruyter92 2026-23-01: Copied from the original DeepLabCut codebase
101+
# from deeplabcut/pose_estimation_pytorch/modelzoo/utils.py
99102
def load_super_animal_config(
100103
super_animal: str,
101104
model_name: str,
@@ -128,9 +131,7 @@ def load_super_animal_config(
128131
else:
129132
model_config["method"] = "TD"
130133
if super_animal != "superanimal_humanbody":
131-
detector_cfg_path = get_super_animal_model_config_path(
132-
model_name=detector_name
133-
)
134+
detector_cfg_path = get_super_animal_model_config_path(model_name=detector_name)
134135
detector_cfg = read_config_as_dict(detector_cfg_path)
135136
model_config["detector"] = detector_cfg
136137
return model_config
@@ -159,9 +160,7 @@ def download_super_animal_snapshot(dataset: str, model_name: str) -> Path:
159160
return model_path
160161

161162
try:
162-
download_huggingface_model(
163-
model_name, target_dir=str(snapshot_dir), rename_mapping=model_filename
164-
)
163+
download_huggingface_model(model_name, target_dir=str(snapshot_dir), rename_mapping=model_filename)
165164

166165
if not model_path.exists():
167166
raise RuntimeError(f"Failed to download {model_name} to {model_path}")
@@ -171,5 +170,3 @@ def download_super_animal_snapshot(dataset: str, model_name: str) -> Path:
171170
raise e
172171

173172
return model_path
174-
175-

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,5 @@ target-version = "py310"
9797
fix = true
9898
line-length = 120
9999

100-
[tool.ruff.pydocstyle]
100+
[tool.ruff.lint.pydocstyle]
101101
convention = "google"

tests/test_modelzoo.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
1-
# NOTE JR 2026-23-01: This is duplicate code, copied from the original DeepLabCut-Live codebase.
2-
1+
# NOTE - DUPLICATED @deruyter92 2026-23-01: Copied from the original DeepLabCut codebase
2+
# from deeplabcut/tests/pose_estimation_pytorch/modelzoo/test_modelzoo_utils.py
33
import os
44

5-
import pytest
65
import dlclibrary
6+
import pytest
77
from dlclibrary.dlcmodelzoo.modelzoo_download import MODELOPTIONS
88

99
from dlclive import modelzoo
1010

1111

12-
@pytest.mark.parametrize(
13-
"super_animal", ["superanimal_quadruped", "superanimal_topviewmouse"]
14-
)
12+
@pytest.mark.parametrize("super_animal", ["superanimal_quadruped", "superanimal_topviewmouse"])
1513
@pytest.mark.parametrize("model_name", ["hrnet_w32"])
1614
@pytest.mark.parametrize("detector_name", [None, "fasterrcnn_resnet50_fpn_v2"])
1715
def test_get_config_model_paths(super_animal, model_name, detector_name):
@@ -48,4 +46,4 @@ def test_download_huggingface_wrong_model():
4846
@pytest.mark.skip(reason="slow")
4947
@pytest.mark.parametrize("model", MODELOPTIONS)
5048
def test_download_all_models(tmp_path_factory, model):
51-
test_download_huggingface_model(tmp_path_factory, model)
49+
test_download_huggingface_model(tmp_path_factory, model)

0 commit comments

Comments
 (0)