當前位置: 首頁>>代碼示例>>Python>>正文


Python linear_assignment_.linear_assignment方法代碼示例

本文整理匯總了Python中sklearn.utils.linear_assignment_.linear_assignment方法的典型用法代碼示例。如果您正苦於以下問題:Python linear_assignment_.linear_assignment方法的具體用法?Python linear_assignment_.linear_assignment怎麽用?Python linear_assignment_.linear_assignment使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在sklearn.utils.linear_assignment_的用法示例。


在下文中一共展示了linear_assignment_.linear_assignment方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: acc

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def acc(y_true, y_pred):
    """
    Calculate clustering accuracy. Require scikit-learn installed

    # Arguments
        y: true labels, numpy.array with shape `(n_samples,)`
        y_pred: predicted labels, numpy.array with shape `(n_samples,)`

    # Return
        accuracy, in [0,1]
    """
    y_true = y_true.astype(np.int64)
    assert y_pred.size == y_true.size
    D = max(y_pred.max(), y_true.max()) + 1
    w = np.zeros((D, D), dtype=np.int64)
    for i in range(y_pred.size):
        w[y_pred[i], y_true[i]] += 1
    from sklearn.utils.linear_assignment_ import linear_assignment
    ind = linear_assignment(w.max() - w)
    return sum([w[i, j] for i, j in ind]) * 1.0 / y_pred.size 
開發者ID:XifengGuo,項目名稱:DEC-DA,代碼行數:22,代碼來源:metrics.py

示例2: ceafe

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def ceafe(clusters, gold_clusters):
        u"""
        Computes the  Constrained EntityAlignment F-Measure (CEAF) for evaluating coreference.
        Gold and predicted mentions are aligned into clusterings which maximise a metric - in
        this case, the F measure between gold and predicted clusters.

        <https://www.semanticscholar.org/paper/On-Coreference-Resolution-Performance-Metrics-Luo/de133c1f22d0dfe12539e25dda70f28672459b99>
        """
        clusters = [cluster for cluster in clusters if len(cluster) != 1]
        scores = np.zeros((len(gold_clusters), len(clusters)))
        for i, gold_cluster in enumerate(gold_clusters):
            for j, cluster in enumerate(clusters):
                scores[i, j] = Scorer.phi4(gold_cluster, cluster)
        matching = linear_assignment(-scores)
        similarity = sum(scores[matching[:, 0], matching[:, 1]])
        return similarity, len(clusters), similarity, len(gold_clusters) 
開發者ID:plasticityai,項目名稱:magnitude,代碼行數:18,代碼來源:conll_coref_scores.py

示例3: __init__

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def __init__(self, boxes1, boxes2, labels1=None, labels2=None):
        self._boxes1 = boxes1
        self._boxes2 = boxes2

        if len(boxes1) == 0 or len(boxes2) == 0:
            pass
        else:
            
            if labels1 is None or labels2 is None:
                self._iou_matrix = self._calc(boxes1,
                                              boxes2,
                                              np.ones((len(boxes1),)),
                                              np.ones((len(boxes2),)))
            else:
                self._iou_matrix = self._calc(boxes1, boxes2, labels1, labels2)
            self._match_pairs = linear_assignment(-1*self._iou_matrix) 
開發者ID:penny4860,項目名稱:tf2-eager-yolo3,代碼行數:18,代碼來源:_box_match.py

示例4: cluster_acc

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def cluster_acc(y_true, y_pred):
    """
    Calculate clustering accuracy. Require scikit-learn installed

    # Arguments
        y: true labels, numpy.array with shape `(n_samples,)`
        y_pred: predicted labels, numpy.array with shape `(n_samples,)`

    # Return
        accuracy, in [0,1]
    """
    y_true = y_true.astype(np.int64)
    assert y_pred.size == y_true.size
    D = max(y_pred.max(), y_true.max()) + 1
    w = np.zeros((D, D), dtype=np.int64)
    for i in range(y_pred.size):
        w[y_pred[i], y_true[i]] += 1
    ind = linear_assignment(w.max() - w)
    return sum([w[i, j] for i, j in ind]) * 1.0 / y_pred.size 
開發者ID:k-han,項目名稱:DTC,代碼行數:21,代碼來源:util.py

示例5: cluster_acc

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def cluster_acc(y_true, y_pred):
    """
    Calculate clustering accuracy. Require scikit-learn installed.
    (Taken from https://github.com/XifengGuo/IDEC-toy/blob/master/DEC.py)
    # Arguments
        y: true labels, numpy.array with shape `(n_samples,)`
        y_pred: predicted labels, numpy.array with shape `(n_samples,)`
    # Return
        accuracy, in [0,1]
    """
    y_true = y_true.astype(np.int64)
    assert y_pred.size == y_true.size
    D = max(y_pred.max(), y_true.max()) + 1
    w = np.zeros((D, D), dtype=np.int64)
    for i in range(y_pred.size):
        w[y_pred[i], y_true[i]] += 1
    ind = linear_assignment(w.max() - w) # Optimal label mapping based on the Hungarian algorithm

    return sum([w[i, j] for i, j in ind]) * 1.0 / y_pred.size 
開發者ID:MaziarMF,項目名稱:deep-k-means,代碼行數:21,代碼來源:utils.py

示例6: cluster_acc

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def cluster_acc(Y_pred, Y):
  from sklearn.utils.linear_assignment_ import linear_assignment
  assert Y_pred.size == Y.size
  D = max(Y_pred.max(), Y.max())+1
  w = np.zeros((D,D), dtype=np.int64)
  for i in range(Y_pred.size):
    w[Y_pred[i], int(Y[i])] += 1
  ind = linear_assignment(w.max() - w)
  return sum([w[i,j] for i,j in ind])*1.0/Y_pred.size, w 
開發者ID:awslabs,項目名稱:dynamic-training-with-apache-mxnet-on-aws,代碼行數:11,代碼來源:dec.py

示例7: ceafe

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def ceafe(clusters, gold_clusters):
    clusters = [c for c in clusters if len(c) != 1]
    scores = np.zeros((len(gold_clusters), len(clusters)))
    for i in range(len(gold_clusters)):
        for j in range(len(clusters)):
            scores[i, j] = phi4(gold_clusters[i], clusters[j])
    matching = linear_assignment(-scores)
    similarity = sum(scores[matching[:, 0], matching[:, 1]])
    return similarity, len(clusters), similarity, len(gold_clusters) 
開發者ID:sattree,項目名稱:gap,代碼行數:11,代碼來源:metrics.py

示例8: associate_detections_to_trackers

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def associate_detections_to_trackers(detections,trackers,iou_threshold = 0.3):
  """
  Assigns detections to tracked object (both represented as bounding boxes)

  Returns 3 lists of matches, unmatched_detections and unmatched_trackers
  """
  if(len(trackers)==0):
    return np.empty((0,2),dtype=int), np.arange(len(detections)), np.empty((0,5),dtype=int)
  iou_matrix = np.zeros((len(detections),len(trackers)),dtype=np.float32)

  for d,det in enumerate(detections):
    for t,trk in enumerate(trackers):
      iou_matrix[d,t] = iou(det,trk)
  '''The linear assignment module tries to minimise the total assignment cost.
  In our case we pass -iou_matrix as we want to maximise the total IOU between track predictions and the frame detection.'''
  matched_indices = linear_assignment(-iou_matrix)

  unmatched_detections = []
  for d,det in enumerate(detections):
    if(d not in matched_indices[:,0]):
      unmatched_detections.append(d)
  unmatched_trackers = []
  for t,trk in enumerate(trackers):
    if(t not in matched_indices[:,1]):
      unmatched_trackers.append(t)

  #filter out matched with low IOU
  matches = []
  for m in matched_indices:
    if(iou_matrix[m[0],m[1]]<iou_threshold):
      unmatched_detections.append(m[0])
      unmatched_trackers.append(m[1])
    else:
      matches.append(m.reshape(1,2))
  if(len(matches)==0):
    matches = np.empty((0,2),dtype=int)
  else:
    matches = np.concatenate(matches,axis=0)

  return matches, np.array(unmatched_detections), np.array(unmatched_trackers) 
開發者ID:ZidanMusk,項目名稱:experimenting-with-sort,代碼行數:42,代碼來源:data_association.py

示例9: associate_detections_to_trackers

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def associate_detections_to_trackers(detections, trackers, affinity_mat,
                                     affinity_threshold):
    """
    Assigns detections to tracked object (both represented as bounding boxes)
    Returns 3 lists of matches, unmatched_detections and unmatched_trackers
    """
    if (len(trackers) == 0): return np.empty((0, 2), dtype=int), np.arange(
            len(detections)), np.empty((0, 2), dtype=int)

    matched_indices = linear_assignment(-affinity_mat)

    unmatched_detections = []
    for d, det in enumerate(detections):
        if d not in matched_indices[:, 0]:
            unmatched_detections.append(d)
    unmatched_trackers = []
    for t, trk in enumerate(trackers):
        if t not in matched_indices[:, 1]:
            unmatched_trackers.append(t)

    # filter out matched with low IOU
    matches = []
    for m in matched_indices:
        if affinity_mat[m[0], m[1]] < affinity_threshold:
            unmatched_detections.append(m[0])
            unmatched_trackers.append(m[1])
        else:
            matches.append(m.reshape(1, 2))
    if len(matches) == 0:
        matches = np.empty((0, 2), dtype=int)
    else:
        matches = np.concatenate(matches, axis=0)

    return matches, np.array(unmatched_detections), np.array(unmatched_trackers) 
開發者ID:ucbdrive,項目名稱:3d-vehicle-tracking,代碼行數:36,代碼來源:tracking_utils.py

示例10: associate_detections_to_trackers

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def associate_detections_to_trackers(detections,trackers,iou_threshold = 0.3):
  """
  Assigns detections to tracked object (both represented as bounding boxes)
  Returns 3 lists of matches, unmatched_detections and unmatched_trackers
  """
  if(len(trackers)==0):
    return np.empty((0,2),dtype=int), np.arange(len(detections)), np.empty((0,5),dtype=int)
  iou_matrix = np.zeros((len(detections),len(trackers)),dtype=np.float32)

  for d,det in enumerate(detections):
    for t,trk in enumerate(trackers):
      iou_matrix[d,t] = iou(det,trk)
  matched_indices = linear_assignment(-iou_matrix)

  unmatched_detections = []
  for d,det in enumerate(detections):
    if(d not in matched_indices[:,0]):
      unmatched_detections.append(d)
  unmatched_trackers = []
  for t,trk in enumerate(trackers):
    if(t not in matched_indices[:,1]):
      unmatched_trackers.append(t)

  #filter out matched with low IOU
  matches = []
  for m in matched_indices:
    if(iou_matrix[m[0],m[1]]<iou_threshold):
      unmatched_detections.append(m[0])
      unmatched_trackers.append(m[1])
    else:
      matches.append(m.reshape(1,2))
  if(len(matches)==0):
    matches = np.empty((0,2),dtype=int)
  else:
    matches = np.concatenate(matches,axis=0)

  return matches, np.array(unmatched_detections), np.array(unmatched_trackers) 
開發者ID:Akhtar303,項目名稱:Vehicle-Detection-and-Tracking-Usig-YOLO-and-Deep-Sort-with-Keras-and-Tensorflow,代碼行數:39,代碼來源:sort.py

示例11: cluster_acc

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def cluster_acc(Y_pred, Y):
    from sklearn.utils.linear_assignment_ import linear_assignment
    assert Y_pred.size == Y.size
    D = max(Y_pred.max(), Y.max())+1
    w = np.zeros((D,D), dtype=np.int64)
    for i in range(Y_pred.size):
        w[Y_pred[i], int(Y[i])] += 1
    ind = linear_assignment(w.max() - w)
    return sum([w[i,j] for i,j in ind])*1.0/Y_pred.size, w 
開發者ID:mlperf,項目名稱:training_results_v0.6,代碼行數:11,代碼來源:dec.py

示例12: associate_detections_to_trackers

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def associate_detections_to_trackers(detections,trackers,iou_threshold = 0.3):
  """
  Assigns detections to tracked object (both represented as bounding boxes)

  Returns 3 lists of matches, unmatched_detections and unmatched_trackers
  """
  if(len(trackers)==0):
    return np.empty((0,2),dtype=int), np.arange(len(detections)), np.empty((0,5),dtype=int)
  iou_matrix = np.zeros((len(detections),len(trackers)),dtype=np.float32)

  for d,det in enumerate(detections):
    for t,trk in enumerate(trackers):
      iou_matrix[d,t] = iou(det,trk)
  matched_indices = linear_assignment(-iou_matrix)

  unmatched_detections = []
  for d,det in enumerate(detections):
    if(d not in matched_indices[:,0]):
      unmatched_detections.append(d)
  unmatched_trackers = []
  for t,trk in enumerate(trackers):
    if(t not in matched_indices[:,1]):
      unmatched_trackers.append(t)

  #filter out matched with low IOU
  matches = []
  for m in matched_indices:
    if(iou_matrix[m[0],m[1]]<iou_threshold):
      unmatched_detections.append(m[0])
      unmatched_trackers.append(m[1])
    else:
      matches.append(m.reshape(1,2))
  if(len(matches)==0):
    matches = np.empty((0,2),dtype=int)
  else:
    matches = np.concatenate(matches,axis=0)

  return matches, np.array(unmatched_detections), np.array(unmatched_trackers) 
開發者ID:Guanghan,項目名稱:ROLO,代碼行數:40,代碼來源:sort_yolo.py

示例13: linear_assignment

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def linear_assignment(cost_matrix, thresh):
    """
    Simple linear assignment
    :type cost_matrix: np.ndarray
    :type thresh: float
    :return: matches, unmatched_a, unmatched_b
    """
    if cost_matrix.size == 0:
        return np.empty((0, 2), dtype=int), tuple(range(cost_matrix.shape[0])), tuple(range(cost_matrix.shape[1]))

    cost_matrix[cost_matrix > thresh] = thresh + 1e-4
    indices = linear_assignment_.linear_assignment(cost_matrix)

    return _indices_to_matches(cost_matrix, indices, thresh) 
開發者ID:longcw,項目名稱:MOTDT,代碼行數:16,代碼來源:matching.py

示例14: best_map

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def best_map(l1, l2):
    """
    Permute labels of l2 to match l1 as much as possible
    """
    if len(l1) != len(l2):
        print("L1.shape must == L2.shape")
        exit(0)

    label1 = np.unique(l1)
    n_class1 = len(label1)

    label2 = np.unique(l2)
    n_class2 = len(label2)

    n_class = max(n_class1, n_class2)
    G = np.zeros((n_class, n_class))

    for i in range(0, n_class1):
        for j in range(0, n_class2):
            ss = l1 == label1[i]
            tt = l2 == label2[j]
            G[i, j] = np.count_nonzero(ss & tt)

    A = la.linear_assignment(-G)

    new_l2 = np.zeros(l2.shape)
    for i in range(0, n_class2):
        new_l2[l2 == label2[A[i][1]]] = label1[A[i][0]]
    return new_l2.astype(int) 
開發者ID:jundongl,項目名稱:scikit-feature,代碼行數:31,代碼來源:unsupervised_evaluation.py

示例15: ceafe_matching

# 需要導入模塊: from sklearn.utils import linear_assignment_ [as 別名]
# 或者: from sklearn.utils.linear_assignment_ import linear_assignment [as 別名]
def ceafe_matching(clusters, gold_clusters):
    clusters = [c for c in clusters if len(c) != 1]
    scores = np.zeros((len(gold_clusters), len(clusters)))
    for i in range(len(gold_clusters)):
        for j in range(len(clusters)):
            scores[i, j] = phi4(gold_clusters[i], clusters[j])
    return linear_assignment(-scores), scores 
開發者ID:kkjawz,項目名稱:coref-ee,代碼行數:9,代碼來源:metrics.py


注:本文中的sklearn.utils.linear_assignment_.linear_assignment方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。