sort icon indicating copy to clipboard operation
sort copied to clipboard

TypeError: tuple indices must be integers or slices, not tuple

Open adityamukherjee42 opened this issue 3 years ago • 7 comments

i have been facing this issue not able to know which line please help TypeError Traceback (most recent call last) in 26 if detections is not None: 27 detections=np.array(detections) ---> 28 tracked_objects = mot_tracker.update(detections) 29 detections=torch.from_numpy(detections) 30 unique_labels = detections[:, -1].cpu().unique()

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

adityamukherjee42 avatar May 22 '21 15:05 adityamukherjee42

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?

InputBlackBoxOutput avatar Jun 12 '21 09:06 InputBlackBoxOutput

No man still trying to

adityamukherjee42 avatar Jun 13 '21 17:06 adityamukherjee42

@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

InputBlackBoxOutput avatar Jun 19 '21 05:06 InputBlackBoxOutput

@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?

cocoph avatar Aug 04 '21 09:08 cocoph

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.

  1. Comment out the import
# from scipy.optimize import linear_sum_assignment as linear_assignment
  1. Use pip to install lap

  2. Copy and paste the above function in the sort.py file

InputBlackBoxOutput avatar Aug 04 '21 10:08 InputBlackBoxOutput

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.

  1. Comment out the import
# from scipy.optimize import linear_sum_assignment as linear_assignment
  1. Use pip to install lap
  2. Copy and paste the above function in the sort.py file

It's working now, many thanks

cocoph avatar Aug 04 '21 18:08 cocoph

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

vkavin4201 avatar Jul 04 '22 06:07 vkavin4201