Open yifanzhang666777 opened 3 years ago
This happened to me when I changed:
from sklearn.utils.linear_assignment_ import linear_assignment
to from scipy.optimize import linear_sum_assignment as linear_assignment
Because sklearn's linear_assignment
has been removed starting with version "0.23.0" and higher, I opted for Scipy's implementation of the function (which returns a tuple of np vectors as opposed to a matrix) (click here to learn more).
Thus, to get the equivalent result as if we were using sklearn's implementation I modified sort.py
with below code:
import sklearn
skver = int(sklearn.__version__[2:4]) # extract middle number of version with format \d.\d\d.\d\d
if skver >= 23:
from scipy.optimize import linear_sum_assignment as linear_assignment
sk = False # we will not use sklearn implementation
else:
from sklearn.utils.linear_assignment_ import linear_assignment
sk = True # we will use sklearn implementation
# Below code was written after the `matched_indices` object had been created under the `associate_detections_to_trackers` function
matched_indices = linear_assignment(-iou_matrix)
# standardize output to match sklearn implementation if using scipy
if sk == False:
row, col = matched_indices
matched_indices = np.concatenate((row.reshape(-1,1), col.reshape(-1,1)), axis = 1)
Below code highlights the differences between the two implementations:
# sklearn implementation
from sklearn.utils.linear_assignment_ import linear_assignment
import numpy as np
cost = np.array([[4, 1, 3], [2, 0, 5], [3, 2, 2]])
result = linear_assignment(cost)
result # array([[0, 1],
# [1, 0],
# [2, 2]])
# scipy implementation
import numpy as np
from scipy.optimize import linear_sum_assignment as linear_assignment
cost = np.array([[4, 1, 3], [2, 0, 5], [3, 2, 2]])
result = linear_assignment(cost)
result # (array([0, 1, 2]), array([1, 0, 2], dtype=int64))
row, col = result
result = np.concatenate((row.reshape(-1,1), col.reshape(-1,1)), axis = 1)
result # array([[0, 1],
# [1, 0],
# [2, 2]], dtype=int64)
This happened to me when I changed:
from sklearn.utils.linear_assignment_ import linear_assignment
tofrom scipy.optimize import linear_sum_assignment as linear_assignment
Because sklearn's
linear_assignment
has been removed starting with version "0.23.0" and higher, I opted for Scipy's implementation of the function (which returns a tuple of np vectors as opposed to a matrix) (click here to learn more).Thus, to get the equivalent result as if we were using sklearn's implementation I modified
sort.py
with below code:import sklearn skver = int(sklearn.__version__[2:4]) # extract middle number of version with format \d.\d\d.\d\d if skver >= 23: from scipy.optimize import linear_sum_assignment as linear_assignment sk = False # we will not use sklearn implementation else: from sklearn.utils.linear_assignment_ import linear_assignment sk = True # we will use sklearn implementation # Below code was written after the `matched_indices` object had been created under the `associate_detections_to_trackers` function matched_indices = linear_assignment(-iou_matrix) # standardize output to match sklearn implementation if using scipy if sk == False: row, col = matched_indices matched_indices = np.concatenate((row.reshape(-1,1), col.reshape(-1,1)), axis = 1)
Below code highlights the differences between the two implementations:
# sklearn implementation from sklearn.utils.linear_assignment_ import linear_assignment import numpy as np cost = np.array([[4, 1, 3], [2, 0, 5], [3, 2, 2]]) result = linear_assignment(cost) result # array([[0, 1], # [1, 0], # [2, 2]]) # scipy implementation import numpy as np from scipy.optimize import linear_sum_assignment as linear_assignment cost = np.array([[4, 1, 3], [2, 0, 5], [3, 2, 2]]) result = linear_assignment(cost) result # (array([0, 1, 2]), array([1, 0, 2], dtype=int64)) row, col = result result = np.concatenate((row.reshape(-1,1), col.reshape(-1,1)), axis = 1) result # array([[0, 1], # [1, 0], # [2, 2]], dtype=int64)
Sorry,I met the same problem. But I'm not quite understand where's sort.py
and how to modify it?
This happened to me when I changed:
from sklearn.utils.linear_assignment_ import linear_assignment
tofrom scipy.optimize import linear_sum_assignment as linear_assignment
Because sklearn's
linear_assignment
has been removed starting with version "0.23.0" and higher, I opted for Scipy's implementation of the function (which returns a tuple of np vectors as opposed to a matrix) (click here to learn more).Thus, to get the equivalent result as if we were using sklearn's implementation I modified
sort.py
with below code:import sklearn skver = int(sklearn.__version__[2:4]) # extract middle number of version with format \d.\d\d.\d\d if skver >= 23: from scipy.optimize import linear_sum_assignment as linear_assignment sk = False # we will not use sklearn implementation else: from sklearn.utils.linear_assignment_ import linear_assignment sk = True # we will use sklearn implementation # Below code was written after the `matched_indices` object had been created under the `associate_detections_to_trackers` function matched_indices = linear_assignment(-iou_matrix) # standardize output to match sklearn implementation if using scipy if sk == False: row, col = matched_indices matched_indices = np.concatenate((row.reshape(-1,1), col.reshape(-1,1)), axis = 1)
Below code highlights the differences between the two implementations:
# sklearn implementation from sklearn.utils.linear_assignment_ import linear_assignment import numpy as np cost = np.array([[4, 1, 3], [2, 0, 5], [3, 2, 2]]) result = linear_assignment(cost) result # array([[0, 1], # [1, 0], # [2, 2]]) # scipy implementation import numpy as np from scipy.optimize import linear_sum_assignment as linear_assignment cost = np.array([[4, 1, 3], [2, 0, 5], [3, 2, 2]]) result = linear_assignment(cost) result # (array([0, 1, 2]), array([1, 0, 2], dtype=int64)) row, col = result result = np.concatenate((row.reshape(-1,1), col.reshape(-1,1)), axis = 1) result # array([[0, 1], # [1, 0], # [2, 2]], dtype=int64)
I got to know that we were talking about the different project, so i opened a new issue https://github.com/yehengchen/Object-Detection-and-Tracking/issues/98#issue-860893050.
could you please give me a hand?
row, col = result
this worked for me,thank you
If you encountered a problem in the linear_assignment.py try adding that extra second line.
Mine is for a different project, but the error was same for me.
indices = linear_assignment(cost_matrix) indices = np.hstack([indices[0].reshape(((indices[0].shape[0]), 1)),indices[1].reshape(((indices[0].shape[0]), 1))])
hope it helps :)
if(d not in matched_indices[:,0]): TypeError: tuple indices must be integers or slices, not tuple