Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

add backgroud class in box_nms #14058

Merged
merged 3 commits into from
Mar 11, 2019
Merged

add backgroud class in box_nms #14058

merged 3 commits into from
Mar 11, 2019

Conversation

arcadiaphy
Copy link
Member

Description

This PR is mentioned in #14057

What I have done in box_nms operator:

  1. add background_id argument
  2. filter out background boxes before sorting operation

Checklist

Essentials

Please feel free to remove inapplicable items for your PR.

  • The PR title starts with [MXNET-$JIRA_ID], where $JIRA_ID refers to the relevant JIRA issue created (except PRs with tiny changes)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage:
  • Unit tests are added for small changes to verify correctness (e.g. adding a new operator)
  • Nightly tests are added for complicated/long-running ones (e.g. changing distributed kvstore)
  • Build tests will be added for build configuration changes (e.g. adding a new build option with NCCL)
  • Code is well-documented:
  • For user-facing API changes, API doc string has been updated.
  • For new C++ functions in header files, their functionalities and arguments are documented.
  • For new examples, README.md is added to explain the what the example does, the source of the dataset, expected performance on test set and reference to the original paper if applicable
  • Check the API doc at http://mxnet-ci-doc.s3-accelerate.dualstack.amazonaws.com/PR-$PR_ID/$BUILD_ID/index.html
  • To the my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Feature1, tests, (and when applicable, API doc)
  • Feature2, tests, (and when applicable, API doc)

Comments

  • If this change is a backward incompatible change, why must this change be made.
  • Interesting edge cases to note here

@arcadiaphy arcadiaphy force-pushed the fix_nms branch 3 times, most recently from eacda4d to 7849b3b Compare February 2, 2019 13:35
@vandanavk
Copy link
Contributor

@mxnet-label-bot add [pr-awaiting-review, Operator]

@marcoabreu marcoabreu added Operator pr-awaiting-review PR is waiting for code review labels Feb 4, 2019
Copy link
Contributor

@ChaiBapchya ChaiBapchya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retrigger the CI as the CI issue of test_stn has been fixed 2 days back by #14063

git commit --allow-empty -m "Trigger notification"

@@ -106,7 +109,7 @@ inline bool BoxNMSShape(const nnvm::NodeAttrs& attrs,
<< ishape << " provided";
int width_elem = ishape[indim - 1];
int expected = 5;
if (param.id_index > 0) {
if (param.id_index >= 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious to know why this change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the valid id_index should be >= 0 instead of just > 0. Surely, this line is not relevant to this PR.

@ChaiBapchya
Copy link
Contributor

ChaiBapchya commented Feb 5, 2019

@mxnet-label-bot update [pr-awaiting-response, Operator]

@marcoabreu marcoabreu added pr-awaiting-response PR is reviewed and waiting for contributor to respond Operator and removed Operator pr-awaiting-review PR is waiting for code review labels Feb 5, 2019
@arcadiaphy arcadiaphy force-pushed the fix_nms branch 2 times, most recently from 943ea0d to f36efee Compare February 7, 2019 11:41
@ankkhedia
Copy link
Contributor

@apeforest @samskalicky Coul d you please help review this PR?

@anirudhacharya
Copy link
Member

@arcadiaphy please add tests for these changes.

Copy link
Member

@wkcn wkcn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent. Thanks for your contribution!
LGTM: )

@arcadiaphy
Copy link
Member Author

@wkcn CI seems OK now, ready for merge.

@wkcn wkcn added pr-awaiting-merge Review and CI is complete. Ready to Merge and removed pr-awaiting-response PR is reviewed and waiting for contributor to respond labels Mar 6, 2019
Copy link
Member

@zhreshold zhreshold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would marking scores of all boxes with background_id to 0 or -1 simpler and don't require any operator change?

@arcadiaphy
Copy link
Member Author

@zhreshold Currently there are no background_id logic in box_nms operator on prefiltering or nms step, so a lot of time is wasted in processing background boxes.

To keep operator unchanged, background boxes need to be removed in NDArray input.

@zhreshold
Copy link
Member

@arcadiaphy Yes, a pre-filtering can be much easier, but there's no guarantee that box_nms will always have clean input. So I am actually convinced this is good to go. BTW, do you have the new validation time with this new PR?

@arcadiaphy
Copy link
Member Author

arcadiaphy commented Mar 6, 2019

@zhreshold Sometimes the validation time of SSD_512 on voc dataset is more than half an hour before, much longer than training time.

I have written a simple script to show benchmark:

import mxnet as mx
import numpy as np
import time

np.random.seed(0)
ctx = mx.gpu(0)

def test_nms(background_ratio):
    batch_size = 32
    prior_number = 100000  # SSD_512 has more than 100k prior boxes
    background_number = int(prior_number * background_ratio)
    data = np.zeros((batch_size, prior_number, 6))
    data[:, :, 0] = 0
    data[:, :background_number, 0] = -1
    data[:, :, 1] = np.random.random((batch_size, prior_number))

    xmin = np.random.random((batch_size, prior_number))
    ymin = np.random.random((batch_size, prior_number))
    width = np.random.random((batch_size, prior_number))
    height = np.random.random((batch_size, prior_number))
    data[:, :, 2] = xmin
    data[:, :, 3] = ymin
    data[:, :, 4] = xmin + width
    data[:, :, 5] = ymin + height

    mx_data = mx.nd.array(data, ctx=ctx)
    start = time.time()
    rv = mx.nd.contrib.box_nms(mx_data, overlap_thresh=0.5, valid_thresh=0, topk=400, id_index=0, score_index=1, coord_start=2, background_id=-1)
    mx.nd.waitall()
    print 'background ratio {} process time: {} s'.format(background_ratio, time.time() - start)


test_nms(0)
test_nms(0.5)
test_nms(0.9)
test_nms(0.99)

The output on TITAN X (Pascal):

background ratio 0 process time: 22.8679060936 s
background ratio 0.5 process time: 10.5633630753 s
background ratio 0.9 process time: 1.97785997391 s
background ratio 0.99 process time: 0.20063495636 s

@zhreshold
Copy link
Member

@arcadiaphy Please also take a look at two improvements contributed by @ptrendx
#14352 #14290

Copy link
Member

@zhreshold zhreshold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waiting for justification of the added API

@arcadiaphy
Copy link
Member Author

arcadiaphy commented Mar 7, 2019

@zhreshold My PR is complementary to the great improvements of @ptrendx on cuda kernels. After combining all three PRs, box_nms is close to the original MultiBoxDetection operator.

@zhreshold
Copy link
Member

@arcadiaphy Please resolve the conflict and it's good to go. 😺

@arcadiaphy
Copy link
Member Author

@zhreshold OK to go now.

@zhreshold zhreshold merged commit 2df5756 into apache:master Mar 11, 2019
@zhreshold
Copy link
Member

thanks @arcadiaphy , this is merged

@arcadiaphy arcadiaphy deleted the fix_nms branch March 11, 2019 09:15
vdantu pushed a commit to vdantu/incubator-mxnet that referenced this pull request Mar 31, 2019
* add backgroud class in box_nms

* add unittest

* trigger CI
nswamy pushed a commit that referenced this pull request Apr 5, 2019
* add backgroud class in box_nms

* add unittest

* trigger CI
haohuanw pushed a commit to haohuanw/incubator-mxnet that referenced this pull request Jun 23, 2019
* add backgroud class in box_nms

* add unittest

* trigger CI
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Operator pr-awaiting-merge Review and CI is complete. Ready to Merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants