Skip to content

Commit e84468e

Browse files
committed
Handle multi-animal data with unique body parts
1 parent 67918bc commit e84468e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/napari_deeplabcut/misc.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,20 @@ def merge_multiple_scorers(
3636
if n_scorers == 1:
3737
return df
3838

39-
n_bodyparts = len(header.bodyparts)
4039
if "likelihood" in header.coords:
4140
# Merge annotations from multiple scorers to keep
4241
# detections with highest confidence
43-
data = df.to_numpy().reshape((n_frames, n_scorers, n_bodyparts, -1))
44-
idx = np.nanargmax(data[..., 2], axis=1)
42+
data = df.to_numpy().reshape((n_frames, n_scorers, -1, 3))
43+
try:
44+
idx = np.nanargmax(data[..., 2], axis=1)
45+
except ValueError: # All-NaN slice encountered
46+
mask = np.isnan(data[..., 2]).all(axis=1, keepdims=True)
47+
mask = np.broadcast_to(mask[..., None], data.shape)
48+
data[mask] = -1
49+
idx = np.nanargmax(data[..., 2], axis=1)
50+
data[mask] = np.nan
4551
data_best = data[
46-
np.arange(n_frames)[:, None], idx, np.arange(n_bodyparts)
52+
np.arange(n_frames)[:, None], idx, np.arange(data.shape[2])
4753
].reshape((n_frames, -1))
4854
df = pd.DataFrame(
4955
data_best,

0 commit comments

Comments
 (0)