remydubois / lsnms

Large Scale Non maximum Suppression. This project implements a O(nlog(n)) approach for non max suppression, useful for object detection ran on very large images such as satellite or histology, when the number of instances to prune becomes very large.
63 stars 5 forks source link

Issue with Score Thresholding in _nms #19

Closed chottAA5208 closed 1 year ago

chottAA5208 commented 1 year ago

Hey Remy! Found small bug in your code that should be an easy fix!

In the return np.array(keep) in line 74 of lsnms.nms.py keep is in relation to the subsetted scores/boxes of by the score_threshold score. However, in the end, it needs to refer to the full scores/boxes np.arrays provided as inputs.

if this line is changed to return np.argwhere(score_mask)[keep] the correct indices of the original (unsubsetted) np.arrays will be returned.

For an example input for which this fails and for which this fix will successfully pass is:

` 'nms_test_dict': (

boxes

    np.array(
        [
            [ 11.485742568969727, 15.995068550109863, 1053.8431396484375, 1074.7838134765625], 
            [ 11.485742568969727, 15.995068550109863, 1053.8431396484375, 1074.7838134765625], 
            [ 623.4799194335938, 391.9401550292969, 675.8385009765625, 445.08367919921875], 
        ]
    ),
    #scores 
    np.array([0.054, 0.154, 0.034]),
    #labels 
    np.array([1, 27, 23]),
    #score threshold 
    0.1,
    # total to keep  
    1, 
), `
remydubois commented 1 year ago

Hi,

You are absolutely right. I am sorry for the bug, I poorly designed the related test which made it pass.

Feel to open a PR for that, or I’ll do it in a day or two.

chottAA5208 commented 1 year ago

Thanks Remy!

See https://github.com/remydubois/lsnms/pull/20.

Again, thanks for the great repo. We have greatly appreciated the speedups this has provided to our codebase.


From: Rémy Dubois @.> Sent: Wednesday, July 26, 2023 2:13 PM To: remydubois/lsnms @.> Cc: Chott, Taylor - US @.>; Author @.> Subject: Re: [remydubois/lsnms] Issue with Score Thresholding in _nms (Issue #19)

EXTERNAL EMAIL - This email originated from outside of CACI. Do not click any links or attachments unless you recognize and trust the sender.

Hi,

You are absolutely right. I am sorry for the bug, I poorly designed the related testhttps://github.com/remydubois/lsnms/blob/e3daad82b7a2415d2f4ac6e23382052092d09dfd/tests/test_nms.py#L10 which made it pass.

Feel to open a PR for that, or I’ll do it in a day or two.

— Reply to this email directly, view it on GitHubhttps://github.com/remydubois/lsnms/issues/19#issuecomment-1652429393, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKGVYIJTYMLDJ4CPLMX5G53XSF27NANCNFSM6AAAAAA2Y5ZMMI. You are receiving this because you authored the thread.Message ID: @.***>


This electronic message contains information from CACI International Inc or subsidiary companies, which may be company sensitive, proprietary, privileged or otherwise protected from disclosure. The information is intended to be used solely by the recipient(s) named above. If you are not an intended recipient, be aware that any review, disclosure, copying, distribution or use of this transmission or its contents is prohibited. If you have received this transmission in error, please notify the sender immediately.

remydubois commented 1 year ago

Hi,

so sorry for the inactivity on this, I'm having little bandwidth those days.

If this fix is critical for you, I suggest you just filter boxes on your side, before feeding them to lsnms.nms, and use your snippet to retrieve original indices:

from lsnms import nms
import numpy as np

score_mask , *_ = np.where(scores > threshold)

filtered_idxs = nms(boxes=boxes[score_mask], scores=scores[score_mask], score_threshold=0.)

keep = score_mask[filtered_idxs]

I edited your PR with comments to make compilation pass (although test still need to be fixed I think).