Visitar URL original
Fix `adapt_labeled_data_to_new_project` crash and labeled-data folder lookup by MohammadHijjawi97 · Pull Request #3532 · DeepLabCut/DeepLabCut · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix adapt_labeled_data_to_new_project crash and video folder lookup
adapt_labeled_data_to_new_project raised
"AttributeError: type object 'tqdm' has no attribute 'tqdm'" on its first
line of work, because the module imports the tqdm class rather than the
module. Call tqdm directly.

The labeled-data folder name was also derived by splitting the video path on
"\\" only, so for forward-slash paths (every Linux/macOS project) the whole
path was joined onto labeled-data and the folder was not found. Use
PureWindowsPath(video).stem, which accepts both separators and matches the
folder names DeepLabCut creates (Path(video).stem), including video names
that contain dots.
  • Loading branch information
MohammadHijjawi97 committed Sep 28, 2026
commit 2c9397e3eee9e68024777fbd82455b80115b1e4c
10 changes: 5 additions & 5 deletions deeplabcut/utils/conversioncode.py

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A note about this file: the PR that added it never added the required imports.

It's only the ruff pass that added them, and for tqdm it added the wrong one, hence the failure. But this function was never used or usable anywhere, this actually enables it for the first time

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#

from itertools import islice
from pathlib import Path
from pathlib import Path, PureWindowsPath

import numpy as np
import pandas as pd
Expand Down Expand Up @@ -119,12 +119,12 @@ def adapt_labeled_data_to_new_project(
# Iterate over each labeled data video

# Use tqdm for a progress bar
for video in tqdm.tqdm(cfg["video_sets"]):
for video in tqdm(cfg["video_sets"]):
print("Video:", video)

video_name = video.split("\\")[-1]
# discard the file extension
video_name = video_name.split(".")[0]
# PureWindowsPath accepts both "\\" and "/" separators, so the video name is
# found regardless of the OS the project was created on.
video_name = PureWindowsPath(video).stem

@C-Achard C-Achard Sep 29, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context: this is a rogue surviving pattern from #3421 . I would recommend handling it with Path.stem to avoid creating a special case here (if we end up keeping the func)

# Load the csv file
label_path = Path(project_path) / "labeled-data" / video_name
csv_files = [f.name for f in label_path.iterdir() if f.name.endswith(".csv")]
Expand Down
44 changes: 44 additions & 0 deletions tests/test_conversioncode.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
#
import os

import numpy as np
import pandas as pd
import pytest

from deeplabcut.core.config import ProjectConfig
from deeplabcut.utils import conversioncode


Expand All @@ -27,3 +30,44 @@ def test_guarantee_multiindex_rows(test_data_dir):
assert df.index.nlevels == 3
assert all(df.index.get_level_values(0) == "labeled-data")
assert all(img.endswith(".png") for img in df.index.get_level_values(2))


@pytest.mark.parametrize(
"video",
[
"/data/videos/mouse1.mp4",
r"C:\data\videos\mouse1.mp4",
],
)
def test_adapt_labeled_data_to_new_project_adds_new_bodyparts(tmp_path, video):
config_path = tmp_path / "config.yaml"
ProjectConfig(
Task="task",
scorer="me",
project_path=tmp_path,
multianimalproject=True,
bodyparts="MULTI!",
individuals=["mus1", "mus2"],
multianimalbodyparts=["nose", "tail", "ear"],
video_sets={video: {"crop": "0, 100, 0, 100"}},
).to_yaml(config_path)

# Synthetic labels annotated before "ear" was added to the project
folder = tmp_path / "labeled-data" / "mouse1"
folder.mkdir(parents=True)
columns = pd.MultiIndex.from_product(
[["me"], ["mus1", "mus2"], ["nose", "tail"], ["x", "y"]],
names=["scorer", "individuals", "bodyparts", "coords"],
)
index = pd.MultiIndex.from_tuples([("labeled-data", "mouse1", f"img{i}.png") for i in range(3)])
df = pd.DataFrame(np.arange(24, dtype=float).reshape(3, 8), index=index, columns=columns)
df.to_csv(folder / "CollectedData_me.csv")

conversioncode.adapt_labeled_data_to_new_project(config_path)

adapted = pd.read_hdf(folder / "CollectedData_me.h5")
for individual in ("mus1", "mus2"):
bodyparts = adapted.xs(individual, level="individuals", axis=1).columns.get_level_values("bodyparts")
assert list(bodyparts.unique()) == ["nose", "tail", "ear"]
assert adapted.xs((individual, "ear"), level=("individuals", "bodyparts"), axis=1).isna().all().all()
pd.testing.assert_frame_equal(adapted.loc[:, df.columns], df, check_names=False)