tensorflow / tfjs

A WebGL accelerated JavaScript library for training and deploying ML models.
https://js.tensorflow.org
Apache License 2.0
18.27k stars 1.92k forks source link

nonMaxSuppressionAsync extremely slow #8320

Open JijaProGamer opened 5 days ago

JijaProGamer commented 5 days ago

I use nonMaxSuppressionAsync in my code for getting rid of useless bounding boxes from a detection model, but this simple line of code:

console.time("nms") const nms = await tf.image.nonMaxSuppressionAsync(boxes, scores, 30, detectionSettings.iouThreshold, detectionSettings.scoreThreshold); console.timeEnd("nms")

Takes 20ms !!! That's 4 times the duration of the actual model running:

console.time("model") const res = model.execute(imgTensor); console.timeEnd("model")

since the model is pretty small and only 256x256, I would expect it to be slow, but nonMaxSuppressionAsync should be fast even with thousands of bounding boxes, I cannot implement one myself because tensor.data() for the boxes, scores and classes seem to take out 32 ms out of themselfs, even more than NMS

gaikwadrahul8 commented 4 days ago

Hi, @JijaProGamer

I apologize for the delayed response and thank you for bringing this issue to our attention, could you please help us with minimal code snippet/codepen example or your Github repo with complete steps to replicate the same behavior from our end to investigate this issue further as soon as possible ?

Thank you for your cooperation and patience.

JijaProGamer commented 4 days ago

Hi, @JijaProGamer

I apologize for the delayed response and thank you for bringing this issue to our attention, could you please help us with minimal code snippet/codepen example or your Github repo with complete steps to replicate the same behavior from our end to investigate this issue further as soon as possible ?

Thank you for your cooperation and patience.

I'll reply one ASAP as I get home in a hour or two, thanks

JijaProGamer commented 4 days ago

I've made a small github repo (100 lines of code) so you can debug it fastly - https://github.com/JijaProGamer/NMS-Issue/blob/master/page.html

Just download the html file, press to upload a image, and for the second upload look at the console at console.time for NMS and Model. For images smaller than 512x512 the model takes 15ms or under, while NMS takes in a good case 10MS, and usually up to 20-25MS (rx 6750 xt, i5 12600kf, 32GB Ram if specs needed).

JijaProGamer commented 2 days ago

Any progress on this issue?