@@ -36,14 +36,20 @@ def merge_multiple_scorers(
36
36
if n_scorers == 1 :
37
37
return df
38
38
39
- n_bodyparts = len (header .bodyparts )
40
39
if "likelihood" in header .coords :
41
40
# Merge annotations from multiple scorers to keep
42
41
# 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
45
51
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 ] )
47
53
].reshape ((n_frames , - 1 ))
48
54
df = pd .DataFrame (
49
55
data_best ,
0 commit comments