metrics.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:facade-segmentation 作者: jfemiani 项目源码 文件源码
def match_objects_uniquely(candidates, targets, threshold=0.5):
    g = nx.Graph()
    for t in targets:
        g.add_node(t)
    for c in candidates:
        g.add_node(c)

    for t in targets:
        tbb = BBox(*t.bbox)
        for c in candidates:
            cbb = BBox(*c.bbox)
            intersection = tbb.intersection(cbb).area
            union = tbb.area + cbb.area - intersection

            try:
                current_iou = intersection / float(union)
            except ZeroDivisionError:
                current_iou = float('inf')
                pass

            if current_iou >= threshold:
                g.add_edge(t, c, weight=current_iou)

    target_set = set(targets)
    matching = nx.max_weight_matching(g, maxcardinality=True)  # <- a dict with  v->c and c->v both
    hits = [(t, c) for (t, c) in matching.items() if t in target_set]
    return hits
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号