Skip to content

Instantly share code, notes, and snippets.

@syshen
Created May 19, 2018 12:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • 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
},
@Spichon
Copy link

Spichon commented May 12, 2020

Hi syshen,
In your file, you have self.box_iou(), but you haven't instantiated this part.
Do you have in you possession the following please ?

@ppeelman
Copy link

I would suspect that box_iou is related to calculating the overlap, you can use a library like this: https://www.npmjs.com/package/rectangle-overlap

@RobinDong
Copy link

Very good example!

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