Skip to content

Commit 9011b36

Browse files
committed
fixed consensus bug of skipping instances
1 parent 0d8bdde commit 9011b36

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

superannotate/consensus_benchmark/helpers.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,32 +80,43 @@ def image_consensus(df, image_name, annot_type):
8080
"Invalid %s instance occured, skipping to the next one.",
8181
annot_type
8282
)
83+
visited_instances = {}
84+
for proj, instances in projects_shaply_objs.items():
85+
visited_instances[proj] = [False] * len(instances)
8386

8487
# match instances
8588
for curr_proj, curr_proj_instances in projects_shaply_objs.items():
86-
for curr_inst_data in curr_proj_instances:
89+
for curr_id, curr_inst_data in enumerate(curr_proj_instances):
8790
curr_inst, curr_class, _, _ = curr_inst_data
91+
if visited_instances[curr_proj][curr_id] == True:
92+
continue
8893
max_instances = []
8994
for other_proj, other_proj_instances in projects_shaply_objs.items(
9095
):
9196
if curr_proj == other_proj:
9297
max_instances.append((curr_proj, *curr_inst_data))
93-
projects_shaply_objs[curr_proj].remove(curr_inst_data)
98+
visited_instances[curr_proj][curr_id] = True
9499
else:
95100
if annot_type in ['polygon', 'bbox']:
96101
max_score = 0
97102
else:
98103
max_score = float('-inf')
99104
max_inst_data = None
100-
for other_inst_data in other_proj_instances:
105+
max_inst_id = -1
106+
for other_id, other_inst_data in enumerate(
107+
other_proj_instances
108+
):
101109
other_inst, other_class, _, _ = other_inst_data
110+
if visited_instances[other_proj][other_id] == True:
111+
continue
102112
score = instance_consensus(curr_inst, other_inst)
103113
if score > max_score and other_class == curr_class:
104114
max_score = score
105115
max_inst_data = other_inst_data
116+
max_inst_id = other_id
106117
if max_inst_data is not None:
107118
max_instances.append((other_proj, *max_inst_data))
108-
projects_shaply_objs[other_proj].remove(max_inst_data)
119+
visited_instances[other_proj][max_inst_id] = True
109120
if len(max_instances) == 1:
110121
image_data["creatorEmail"].append(max_instances[0][3])
111122
image_data["attributes"].append(max_instances[0][4])

0 commit comments

Comments
 (0)