用以下代码做实验
import time import cv2 as cv import glob import argparse import sys import numpy as np import os.path from collections import deque from sklearn.utils.linear_assignment_ import linear_assignment ..... ..... for i in range(100): indices = linear_assignment(cost_matrix)
输出显示
DeprecationWarning: The linear_assignment function is deprecated in 0.21 and will be removed from 0.23. Use scipy.optimize.linear_sum_assignment instead.
经过查阅相关资料,代码部分替换为下面形式即可解决
不同之处在于返回格式: linear_assignment()
返回一个 numpy 数组和linear_sum_assignment()
返回 一个 numpy 数组的元组。通过转换 linear_sum_assignment()
输出为array
并转置它,可以获得相同的输出。
import time import cv2 as cv import glob import argparse import sys import numpy as np import os.path from collections import deque from scipy.optimize import linear_sum_assignment # 代替上面 linear_assignment indices = linear_sum_assignment(cost_matrix) indices = np.asarray(indices) indices = np.transpose(indices)