You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This iteration is terminate once we have collected N best hit, or if there are no more hit left to test for overlap
92
92
93
93
INPUT
94
-
- ListHit : a list of dictionnary, with each dictionnary being a hit following the formating {'TemplateIdx'= (int),'BBox'=(x,y,width,height),'Score'=(float)}
95
-
the TemplateIdx is the row index in the panda/Knime table
96
-
97
-
- scoreThreshold : Float (or None), used to remove hit with too low prediction score.
98
-
If sortDescending=True (ie we use a correlation measure so we want to keep large scores) the scores above that threshold are kept
99
-
While if we use sortDescending=False (we use a difference measure ie we want to keep low score), the scores below that threshold are kept
100
-
101
-
- N_object : number of best hit to return (by increasing score). Min=1, eventhough it does not really make sense to do NMS with only 1 hit
102
-
- maxOverlap : float between 0 and 1, the maximal overlap authorised between 2 bounding boxes, above this value, the bounding box of lower score is deleted
103
-
- sortDescending : use True when high score means better prediction, False otherwise (ex : if score is a difference measure, then the best prediction are low difference and we sort by ascending order)
104
-
105
-
OUTPUT
106
-
List_nHit : List of the best detection after NMS, it contains max N detection (but potentially less)
107
-
'''
108
-
109
-
# Apply threshold on prediction score
110
-
ifscoreThreshold==None :
111
-
List_ThreshHit=List_Hit[:] # copy to avoid modifying the input list in place
112
-
113
-
elifsortDescending : # We keep hit above the threshold
# Sort score to have best predictions first (important as we loop testing the best boxes against the other boxes)
121
-
ifsortDescending:
122
-
List_ThreshHit.sort(key=lambdadico: dico['Score'], reverse=True) # Hit = [list of (x,y),score] - sort according to descending (best = high correlation)
123
-
else:
124
-
List_ThreshHit.sort(key=lambdadico: dico['Score']) # sort according to ascending score (best = small difference)
125
-
126
-
127
-
# Split the inital pool into Final Hit that are kept and restHit that can be tested
128
-
# Initialisation : 1st keep is kept for sure, restHit is the rest of the list
129
-
#print("\nInitialise final hit list with first best hit")
130
-
FinalHit= [List_ThreshHit[0]]
131
-
restHit=List_ThreshHit[1:]
132
-
133
-
134
-
# Loop to compute overlap
135
-
whilelen(FinalHit)<N_objectandrestHit : # second condition is restHit is not empty
136
-
137
-
# Report state of the loop
138
-
#print("\n\n\nNext while iteration")
139
-
140
-
#print("-> Final hit list")
141
-
#for hit in FinalHit: print(hit)
142
-
143
-
#print("\n-> Remaining hit list")
144
-
#for hit in restHit: print(hit)
145
-
146
-
# pick the next best peak in the rest of peak
147
-
test_hit=restHit[0]
148
-
test_bbox=test_hit['BBox']
149
-
#print("\nTest BBox:{} for overlap against higher score bboxes".format(test_bbox))
150
-
151
-
# Loop over hit in FinalHit to compute successively overlap with test_peak
152
-
forhitinFinalHit:
153
-
154
-
# Recover Bbox from hit
155
-
bbox2=hit['BBox']
156
-
157
-
# Compute the Intersection over Union between test_peak and current peak
158
-
IoU=computeIoU(test_bbox, bbox2)
159
-
160
-
# Initialise the boolean value to true before test of overlap
161
-
ToAppend=True
162
-
163
-
ifIoU>maxOverlap:
164
-
ToAppend=False
165
-
#print("IoU above threshold\n")
166
-
break# no need to test overlap with the other peaks
167
-
168
-
else:
169
-
#print("IoU below threshold\n")
170
-
# no overlap for this particular (test_peak,peak) pair, keep looping to test the other (test_peak,peak)
171
-
continue
172
-
173
-
174
-
# After testing against all peaks (for loop is over), append or not the peak to final
175
-
ifToAppend:
176
-
# Move the test_hit from restHit to FinalHit
177
-
#print("Append {} to list of final hits, remove it from Remaining hit list".format(test_hit))
178
-
FinalHit.append(test_hit)
179
-
restHit.remove(test_hit)
180
-
181
-
else:
182
-
# only remove the test_peak from restHit
183
-
#print("Remove {} from Remaining hit list".format(test_hit))
184
-
restHit.remove(test_hit)
185
-
186
-
187
-
# Once function execution is done, return list of hit without overlap
188
-
#print("\nCollected N expected hit, or no hit left to test")
189
-
#print("NMS over\n")
190
-
returnFinalHit
191
-
192
-
94
+
- tableHit : (Panda DataFrame) Each row is a hit, with columns "TemplateName"(String),"BBox"(x,y,width,height),"Score"(float)
95
+
96
+
- scoreThreshold : Float (or None), used to remove hit with too low prediction score.
97
+
If sortDescending=True (ie we use a correlation measure so we want to keep large scores) the scores above that threshold are kept
98
+
While if we use sortDescending=False (we use a difference measure ie we want to keep low score), the scores below that threshold are kept
99
+
100
+
- N_object : number of best hit to return (by increasing score). Min=1, eventhough it does not really make sense to do NMS with only 1 hit
101
+
- maxOverlap : float between 0 and 1, the maximal overlap authorised between 2 bounding boxes, above this value, the bounding box of lower score is deleted
102
+
- sortDescending : use True when high score means better prediction, False otherwise (ex : if score is a difference measure, then the best prediction are low difference and we sort by ascending order)
103
+
104
+
OUTPUT
105
+
Panda DataFrame with best detection after NMS, it contains max N detection (but potentially less)
106
+
'''
107
+
108
+
# Apply threshold on prediction score
109
+
ifscoreThreshold==None :
110
+
threshTable=tableHit.copy() # copy to avoid modifying the input list in place
111
+
112
+
elifsortDescending : # We keep rows above the threshold
0 commit comments