Skip to content
Merged
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
42 changes: 24 additions & 18 deletions deeplabcut/benchmark/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@
def _format_gt_data(h5file):
df = pd.read_hdf(h5file)

def _get_unique_level_values(header, level):
return header.get_level_values(level).unique().to_list()

animals = _get_unique_level_values(df.columns, "individuals")
kpts = _get_unique_level_values(df.columns, "bodyparts")
try:
Expand All @@ -64,27 +61,16 @@ def _get_unique_level_values(header, level):
}


def _get_unique_level_values(header, level):
return header.get_level_values(level).unique().to_list()


def calc_prediction_errors(preds, gt):
kpts_gt = gt["metadata"]["keypoints"]
kpts_pred = preds["metadata"]["keypoints"]
map_ = {kpts_gt.index(kpt): i for i, kpt in enumerate(kpts_pred)}
annot = gt["annotations"]

# Map image paths from predicted data to GT as the first are typically
# absolute whereas the latter are relative to the project path.
def _map(strings, substrings):
lookup = dict()
strings_ = strings.copy()
substrings_ = substrings.copy()
while strings_:
string = strings_.pop()
for s in substrings_:
if string.endswith(s):
lookup[string] = s
substrings_.remove(s)
break
return lookup

map_images = _map(list(preds["predictions"]), list(annot))

errors = np.full(
Expand Down Expand Up @@ -124,6 +110,26 @@ def _map(strings, substrings):
return errors



def _map(strings, substrings):
"""
Map image paths from predicted data to GT as the first are typically
absolute whereas the latter are relative to the project path.
"""

lookup = dict()
strings_ = strings.copy()
substrings_ = substrings.copy()
while strings_:
string = strings_.pop()
for s in substrings_:
if string.endswith(s):
lookup[string] = s
substrings_.remove(s)
break
return lookup


def conv_obj_to_assemblies(eval_results_obj, keypoint_names):
"""Convert predictions to deeplabcut assemblies."""
assemblies = {}
Expand Down