I am using python script for people detection. I have the following line in my script:
import time
import cv2 as cv
import glob
import argparse
import sys
import numpy as np
import os.path
from imutils.video import FPS
from collections import deque
from sklearn.utils.linear_assignment_ import linear_assignment
When I run my script I have got the following lines:
/home/user/.local/lib/python3.6/site-packages/sklearn/utils/linear_assignment_.py:127:
DeprecationWarning: The linear_assignment function is deprecated in 0.21 and will be removed from 0.23. Use scipy.optimize.linear_sum_assignment instead.
DeprecationWarning)
Please, advice me how to solve it.
You need to replace the sklearn.utils.linear_assignment_.linear_assignment
function by the scipy.optimize.linear_sum_assignment function
.
The difference is in the return format: linear_assignment()
is returning a numpy array and linear_sum_assignment()
a tuple of numpy arrays. You obtain the same output by converting the output of linear_sum_assignment() in array and transpose it.
Your script should look like this:
import time
import cv2 as cv
import glob
import argparse
import sys
import numpy as np
import os.path
from imutils.video import FPS
from collections import deque
from scipy.optimize import linear_sum_assignment
#compute your cost matrix
indices = linear_sum_assignment(cost_matrix)
indices = np.asarray(indices)
indices = np.transpose(indices)
Replace the linear_assignment for linear_sum_assignment
# from sklearn.utils.linear_assignment_ import linear_assignment
from scipy.optimize import linear_sum_assignment
cost = np.array([[4, 1, 3], [2, 0, 5], [3, 2, 2]])
# result = linear_assignment(cost)
result = linear_sum_assignment(cost)
result = np.array(list(zip(*result)))
https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.linear_sum_assignment.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With