Pārlūkot izejas kodu

improve the caption match algorithm

huazZeng 3 mēneši atpakaļ
vecāks
revīzija
725fdbff1c
1 mainītis faili ar 4 papildinājumiem un 2 dzēšanām
  1. 4 2
      mineru/backend/pipeline/pipeline_magic_model.py

+ 4 - 2
mineru/backend/pipeline/pipeline_magic_model.py

@@ -275,7 +275,8 @@ class MagicModel:
 
 
             fst_idx, fst_kind, left_x, top_y = candidates[0]
-            candidates.sort(key=lambda x: (x[2] - left_x) ** 2 + (x[3] - top_y)**2)
+            fst_bbox = subjects[fst_idx]['bbox'] if fst_kind == SUB_BIT_KIND else objects[fst_idx - OBJ_IDX_OFFSET]['bbox']
+            candidates.sort(key=lambda x: bbox_distance(fst_bbox,subjects[x[0]]['bbox']) if x[1] == SUB_BIT_KIND else bbox_distance(fst_bbox, objects[x[0] - OBJ_IDX_OFFSET]['bbox']))
             nxt = None
 
             for i in range(1, len(candidates)):
@@ -294,7 +295,8 @@ class MagicModel:
             pair_dis = bbox_distance(subjects[sub_idx]['bbox'], objects[obj_idx]['bbox'])
             nearest_dis = float('inf')
             for i in range(N):
-                if i in seen_idx or i == sub_idx:continue
+                # 取消原先算法中 1对1 匹配的偏置
+                # if i in seen_idx or i == sub_idx:continue
                 nearest_dis = min(nearest_dis, bbox_distance(subjects[i]['bbox'], objects[obj_idx]['bbox']))
 
             if pair_dis >= 3*nearest_dis: