Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
adityamukherjee42 opened this issue May 22, 2021 · 7 comments
Open

Comments

@adityamukherjee42
Copy link

adityamukherjee42 commented May 22, 2021

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

@InputBlackBoxOutput
Copy link

InputBlackBoxOutput commented Jun 12, 2021

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?

@adityamukherjee42
Copy link
Author

No man still trying to

@InputBlackBoxOutput
Copy link

InputBlackBoxOutput commented Jun 19, 2021

@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

@cocoph
Copy link

cocoph commented Aug 4, 2021

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

@InputBlackBoxOutput
Copy link

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

@cocoph
Copy link

cocoph commented Aug 4, 2021

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

@vkavin4201
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants