当前位置: 首页>>代码示例>>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;未经允许,请勿转载。