Visitar URL original
Remove unused adapt_labeled_data_to_new_project from conversioncode · DeepLabCut/DeepLabCut@2b7567e · GitHub
Skip to content

Commit 2b7567e

Browse files
Remove unused adapt_labeled_data_to_new_project from conversioncode
The function had no callers and could not run (tqdm.tqdm on the tqdm class). Per maintainer discussion in #3532 it is removed rather than fixed. Also drops the numpy, tqdm and deeplabcut imports that only it used.
1 parent 19bb49e commit 2b7567e

1 file changed

Lines changed: 0 additions & 126 deletions

File tree

‎deeplabcut/utils/conversioncode.py‎

Lines changed: 0 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,8 @@
1212
from itertools import islice
1313
from pathlib import Path
1414

15-
import numpy as np
1615
import pandas as pd
17-
from tqdm import tqdm
1816

19-
import deeplabcut as dlc
2017
from deeplabcut.utils import auxiliaryfunctions
2118
from deeplabcut.utils.auxfun_videos import collect_video_paths
2219

@@ -86,129 +83,6 @@ def convertcsv2h5(config: str | Path, userfeedback=True, scorer=None):
8683
print("Attention:", folder, "does not appear to have labeled data!")
8784

8885

89-
def adapt_labeled_data_to_new_project(
90-
config_path: str | Path,
91-
remove_old_bodyparts=False,
92-
other_scorer=False,
93-
userfeedback=False,
94-
):
95-
"""Given the config.yaml file, this function will convert the labels of an ancient
96-
project to a new project. For this, the labeled data must be in the project folder,
97-
under the labeled-data folder and with the same configuration as all deeplabcut
98-
projects.
99-
100-
Args:
101-
config_path (str): The path to the config.yaml file.
102-
remove_old_bodyparts (bool): If True, old bodyparts not in the new project are
103-
removed from the dataframe. Defaults to False.
104-
other_scorer (bool): If True, the labels will be converted to the new scorer. Defaults to False.
105-
userfeedback (bool): If true the user will be asked specifically
106-
for each folder in labeled-data if the containing csv
107-
shall be converted to hdf format. Defaults to True.
108-
"""
109-
# Load the config file
110-
cfg = dlc.auxiliaryfunctions.read_config(config_path)
111-
112-
# Get the Project path
113-
project_path = cfg["project_path"]
114-
115-
# Get the bodyparts
116-
bodyparts = cfg["multianimalbodyparts"]
117-
print("New Bodyparts:", bodyparts)
118-
119-
# Iterate over each labeled data video
120-
121-
# Use tqdm for a progress bar
122-
for video in tqdm.tqdm(cfg["video_sets"]):
123-
print("Video:", video)
124-
125-
video_name = video.split("\\")[-1]
126-
# discard the file extension
127-
video_name = video_name.split(".")[0]
128-
# Load the csv file
129-
label_path = Path(project_path) / "labeled-data" / video_name
130-
csv_files = [f.name for f in label_path.iterdir() if f.name.endswith(".csv")]
131-
if not csv_files:
132-
print("No csv file in the folder:", label_path)
133-
else:
134-
csv_path = str(label_path / csv_files[0])
135-
df = pd.read_csv(csv_path, header=None)
136-
137-
# get the scorer
138-
if other_scorer:
139-
scorer = cfg["scorer"]
140-
# Change the scorer in the dataframe
141-
df.iloc[0, 3:] = pd.Series([scorer] * len(df.columns[3:]))
142-
143-
else:
144-
scorer = df.iloc[0, 3]
145-
146-
# Get the individuals
147-
individuals = np.unique(df.iloc[1, 3:])
148-
149-
# Get the old bodyparts
150-
old_bodyparts = np.unique(df.iloc[2, 3:])
151-
print("Old bodyparts:", old_bodyparts)
152-
153-
# Get the number of old bodyparts
154-
num_of_old_bodyparts = len(old_bodyparts)
155-
156-
# Bodyparts to add
157-
print("Bodyparts to add:", set(bodyparts) - set(old_bodyparts))
158-
159-
# If a bodypart is missing, add it to the dataframe
160-
for index, bodypart in enumerate(bodyparts):
161-
if bodypart not in old_bodyparts:
162-
num_of_old_bodyparts += 1
163-
for i, individual in enumerate(individuals):
164-
# create the columns for the bodypart, concatenate, the individual, the bodypart, and nan values
165-
x_column = pd.concat(
166-
[
167-
pd.Series(scorer),
168-
pd.Series(individual),
169-
pd.Series(bodypart),
170-
pd.Series("x"),
171-
pd.Series(np.nan, index=df.index),
172-
],
173-
axis=0,
174-
ignore_index=True,
175-
)
176-
y_column = pd.concat(
177-
[
178-
pd.Series(scorer),
179-
pd.Series(individual),
180-
pd.Series(bodypart),
181-
pd.Series("y"),
182-
pd.Series(np.nan, index=df.index),
183-
],
184-
axis=0,
185-
ignore_index=True,
186-
)
187-
# Insert the columns in the dataframe
188-
df.insert(
189-
i * 2 * num_of_old_bodyparts + index * 2 + 3,
190-
"insert_" + bodypart + "_x" + individual,
191-
x_column,
192-
)
193-
df.insert(
194-
i * 2 * num_of_old_bodyparts + index * 2 + 4,
195-
"insert" + bodypart + "_y" + individual,
196-
y_column,
197-
)
198-
199-
# If the old bodyparts are not in the new project, remove them
200-
if remove_old_bodyparts:
201-
for bodypart in old_bodyparts:
202-
if bodypart not in bodyparts:
203-
df = df.drop(df.columns[df.iloc[2, :] == bodypart], axis=1)
204-
205-
# Save the dataframe
206-
df.to_csv(csv_path, index=False, header=False)
207-
208-
# Create/Update the h5 file
209-
convertcsv2h5(config_path, userfeedback=userfeedback)
210-
211-
21286
# TODO: @deruyter92 2026-05-20: this function uses videotype instead of video_extensions.
21387
def analyze_videos_converth5_to_csv(video_folder, videotype=None, listofvideos=False):
21488
"""By default the output poses (when running analyze_videos) are stored as

0 commit comments

Comments
 (0)