abewley / sort

Simple, online, and realtime tracking of multiple objects in a video sequence.
GNU General Public License v3.0
3.92k stars 1.09k forks source link

linear_assignment is deprecated #80

Open mkarliner opened 4 years ago

mkarliner commented 4 years ago

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.

kbaxx commented 4 years ago

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)))

elliottzheng commented 4 years ago

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)
ncrasta commented 3 years ago

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