sort
sort copied to clipboard
TypeError: tuple indices must be integers or slices, not tuple
i have been facing this issue not able to know which line please help
TypeError Traceback (most recent call last)
E:\Football player tracking\sort.py in update(self, dets) 207 208 #update matched trackers with assigned detections --> 209 for t,trk in enumerate(self.trackers): 210 if(t not in unmatched_trks): 211 d = matched[np.where(matched[:,1]==t)[0],0]
E:\Football player tracking\sort.py in associate_detections_to_trackers(detections, trackers, iou_threshold) 150 for d,det in enumerate(detections): 151 if(d not in matched_indices[:,0]): --> 152 unmatched_detections.append(d) 153 unmatched_trackers = [] 154 for t,trk in enumerate(trackers):
TypeError: tuple indices must be integers or slices, not tuple
I am facing a similar issue. I speculate that the code is broken because of sklearn.utils.linear_assignment_ which has to be changed to scipy.optimize.linear_sum_assignment
Code
detections = [[start_point[0], start_point[1], end_point[0], end_point[1], confidence] for (start_point, end_point, label, confidence) in results]
# np.set_printoptions(formatter={'float': lambda x: "{0:0.3f}".format(100)})
dets = np.asarray(detections)
print(dets)
tracks = tracker.update(dets)
Debug output with error:
[]
[]
[]
[]
[]
[]
[]
[[109. 147. 170. 173. 0.50095928]]
[[105. 141. 171. 171. 0.36380956]]
Traceback (most recent call last):
File "C:\Users\admin\Desktop\commits\virtual_line\run.py", line 100, in <module>
tracks = tracker.update(dets)
File "C:\Users\admin\Desktop\commits\virtual_line\sort.py", line 203, in update
matched, unmatched_dets, unmatched_trks = associate_detections_to_trackers(dets,trks)
File "C:\Users\admin\Desktop\commits\virtual_line\sort.py", line 144, in associate_detections_to_trackers
if(d not in matched_indices[:,0]):
TypeError: tuple indices must be integers or slices, not tuple
@adityamukherjee42 Were you able to solve the issue?
No man still trying to
@adityamukherjee42 Found a solution Use pip to install lap Comment out the import and use the following function.
def linear_assignment(cost_matrix):
try:
import lap
_, x, y = lap.lapjv(cost_matrix, extend_cost=True)
return np.array([[y[i], i] for i in x if i >= 0])
except ImportError:
from scipy.optimize import linear_sum_assignment
x, y = linear_sum_assignment(cost_matrix)
return np.array(list(zip(x, y)))
I hope this helps
@adityamukherjee42 Found a solution Use pip to install lap Comment out the import and use the following function.
def linear_assignment(cost_matrix): try: import lap _, x, y = lap.lapjv(cost_matrix, extend_cost=True) return np.array([[y[i], i] for i in x if i >= 0]) except ImportError: from scipy.optimize import linear_sum_assignment x, y = linear_sum_assignment(cost_matrix) return np.array(list(zip(x, y)))
I hope this helps
I'm facing the same issue, can you please explain more where to put those functions?
sklearn.utils.linear_assignment_ was replaced with scipy.optimize.linear_sum_assignment since the latter was pruned in the current version. I found the above function in a previous commit.
Follows these steps to fix the bug.
- Comment out the import
# from scipy.optimize import linear_sum_assignment as linear_assignment
-
Use pip to install lap
-
Copy and paste the above function in the sort.py file
sklearn.utils.linear_assignment_ was replaced with scipy.optimize.linear_sum_assignment since the latter was pruned in the current version. I found the above function in a previous commit.
Follows these steps to fix the bug.
- Comment out the import
# from scipy.optimize import linear_sum_assignment as linear_assignment
- Use pip to install lap
- Copy and paste the above function in the sort.py file
It's working now, many thanks
Facing a ValueError now 33 try: 34 import lap ---> 35 _, x, y = lap.lapjv(cost_matrix, extend_cost=True) 36 return np.array([[y[i], i] for i in x if i >= 0]) 37 except ImportError:
lap/_lapjv.pyx in lap._lapjv.lapjv()
/usr/local/lib/python3.7/dist-packages/numpy/core/_methods.py in _amax(a, axis, out, keepdims, initial, where) 38 def _amax(a, axis=None, out=None, keepdims=False, 39 initial=_NoValue, where=True): ---> 40 return umr_maximum(a, axis, None, out, keepdims, initial, where) 41 42 def _amin(a, axis=None, out=None, keepdims=False,
ValueError: zero-size array to reduction operation maximum which has no identity