Skip to content

Instantly share code, notes, and snippets.

@syshen
Created May 19, 2018 12:43
Show Gist options
  • Save syshen/2bb6cac2116a9390144f027938791050 to your computer and use it in GitHub Desktop.
Save syshen/2bb6cac2116a9390144f027938791050 to your computer and use it in GitHub Desktop.
nonMaxSuppression: function(scores, boxes) {
const self = this
let zipped = []
for (let i = 0; i < scores.length; i++) {
zipped.push([
scores[i], [boxes[4*i], boxes[4*i + 1], boxes[4*i + 2], boxes[4*i + 3]], i
])
}
// sort by score
const sorted = zipped.sort((a, b) => b[0] - a[0])
const selected = []
sorted.forEach(box => {
let toAdd = true
for (let i = 0; i < selected.length; i++) {
const iou = self.box_iou(box[1], selected[i][1])
if (iou > 0.5) {
toAdd = false
}
}
if (toAdd) {
selected.push(box)
}
})
return selected
},
@RobinDong
Copy link

Very good example!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment