sort icon indicating copy to clipboard operation
sort copied to clipboard

linear_assignment is deprecated

Open mkarliner opened this issue 4 years ago • 3 comments

In line 147 of sort.py is a call to sklearn 'linear_assignment'

This throws this message DeprecationWarning: The linear_assignment function is deprecated in 0.21 and will be removed from 0.23. Use scipy.optimize.linear_sum_assignment instead.

mkarliner avatar Dec 05 '19 13:12 mkarliner

i fixed it with the following code:

from scipy.optimize import linear_sum_assignment ... matched_indices = linear_sum_assignment(-iou_matrix) matched_indices = np.array(list(zip(*matched_indices)))

kbaxx avatar Jan 09 '20 10:01 kbaxx

I try the method mentioned by @kbaxx, it works fine in most cases but fails when the matched_indices is an empty list.

    194     unmatched_trackers = []
    195     for t, trk in enumerate(trackers):
--> 196         if t not in matched_indices[:, 1]:
    197             unmatched_trackers.append(t)
    198 

IndexError: too many indices for array

I found the solution in the source code of linear_assignment function, all you need to do is reshape the matched_indices

matched_indices = linear_sum_assignment(-iou_matrix)
matched_indices = np.array(list(zip(*matched_indices)))
matched_indices.shape = (-1, 2)

elliottzheng avatar Mar 20 '20 09:03 elliottzheng

I used https://github.come/gatagat/lap and it works fine.

ncrasta avatar Aug 19 '21 15:08 ncrasta