Visitar URL original
"deeplabcut.filterpredictions" and "deeplabcut.analyze_skeleton" return mappings by rahulporuri · Pull Request #1908 · DeepLabCut/DeepLabCut · GitHub
Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
FEAT: Return mapping from video filename to skeleton dataframe
the analyze_skeleton function now returns a mapping instead of None

	modified:   deeplabcut/post_processing/analyze_skeleton.py
  • Loading branch information
Poruri Sai Rahul
Poruri Sai Rahul committed Jul 16, 2022
commit b6b408d862be7920676851b644ae5762e13b026f
13 changes: 12 additions & 1 deletion deeplabcut/post_processing/analyze_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,13 +230,20 @@ def analyzeskeleton(

Returns
-------
None
video_to_skeleton_df
Dictionary mapping video filepaths to skeleton dataframes.

* If no videos exist, the dictionary will be empty.
* If a video is not analyzed, the corresponding value in the dictionary will be
None.
"""
# Load config file, scorer and videos
cfg = auxiliaryfunctions.read_config(config)
if not cfg["skeleton"]:
raise ValueError("No skeleton defined in the config.yaml.")

video_to_skeleton_df = {}

track_method = auxfun_multianimal.get_track_method(cfg, track_method=track_method)
DLCscorer, DLCscorerlegacy = auxiliaryfunctions.GetScorerName(
cfg,
Expand All @@ -258,11 +265,13 @@ def analyzeskeleton(
)
except FileNotFoundError as e:
print(e)
video_to_skeleton_df[video] = None
continue

output_name = filepath.replace(".h5", f"_skeleton.h5")
if os.path.isfile(output_name):
print(f"Skeleton in video {vname} already processed. Skipping...")
video_to_skeleton_df[video] = pd.read_hdf(output_name, "df_with_missing")
continue

bones = {}
Expand All @@ -279,9 +288,11 @@ def analyzeskeleton(
bones[name] = analyzebone(df[scorer][bp1], df[scorer][bp2])

skeleton = pd.concat(bones, axis=1)
video_to_skeleton_df[video] = skeleton
skeleton.to_hdf(output_name, "df_with_missing", format="table", mode="w")
if save_as_csv:
skeleton.to_csv(output_name.replace(".h5", ".csv"))
return video_to_skeleton_df


if __name__ == "__main__":
Expand Down