Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RandomBBoxCrop to optionally output the indices of the bounding boxes that passed the centroid filter #2374

Merged
merged 6 commits into from
Oct 21, 2020

Conversation

jantonguirao
Copy link
Contributor

Signed-off-by: Joaquin Anton janton@nvidia.com

Why we need this PR?

  • It adds new feature needed to effectively handle segmentation masks together with bounding boxes

What happened in this PR?

Fill relevant points, put NA otherwise. Replace anything inside []

  • What solution was applied:
    Added an optional output to RandomBBoxCrop with the indices of the filtered bounding boxes, so that it can be used to select the relevant masks associated with those (in a different operator)
  • Affected modules and functionalities:
    RandomBBoxCrop
  • Key points relevant for the review:
    All
  • Validation and testing:
    Existing tests
  • Documentation (including examples):
    Docstr updated

JIRA TASK: [DALI-1633]

… that passed the centroid filter

Signed-off-by: Joaquin Anton <janton@nvidia.com>
const auto &labels_in = ws.Input<CPUBackend>(1);
auto &labels_out = ws.Output<CPUBackend>(next_out_idx++);
labels_out.Resize({static_cast<Index>(prospective_crop.bbox_indices.size()), 1});
int64_t i = 0;
Copy link
Contributor

@JanuszL JanuszL Oct 19, 2020

Choose a reason for hiding this comment

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

Unused

@JanuszL
Copy link
Contributor

JanuszL commented Oct 19, 2020

Can you add a test to check if the 4th output is provided and is a subset of id returned by the coco reader?

Edit
I see that the indexes are relative. You should check at least that they are matching the filtered bboxes in the test.

Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
@@ -323,7 +332,13 @@ The values are:
.. note::
If left empty, depending on the number of dimensions ``"WH"`` or ``"WHD"`` will be assumed.
)code",
TensorLayout{""});
TensorLayout{""})
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
TensorLayout{""})
TensorLayout{})

TensorLayout{""})
.AddOptionalArg<bool>(
"output_bbox_indices",
R"code(If set to True, an extra output ``bbox_indices`` will be returned, containing
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
R"code(If set to True, an extra output ``bbox_indices`` will be returned, containing
R"code(If set to True, an extra output will be returned, containing

I don't we have named outputs.

@@ -529,20 +546,21 @@ class RandomBBoxCropImpl : public OpImplBase<CPUBackend> {
bool success = false;
Box<ndim, float> crop{};
std::vector<Box<ndim, float>> boxes;
std::vector<int> labels;
SmallVector<int, 128> bbox_indices;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that's a bit too big an object - perhaps it should be a regular vector instead or at the very least we should be much more conservative wrt static size (8-16, not 128).

bool has_labels)
: success(success), crop(crop) {
assert(boxes_data.size() == labels_data.size() || !has_labels);
SmallVector<int, 128> indices = {})
Copy link
Contributor

Choose a reason for hiding this comment

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

Passing a small vector by value is not a good idea.

Signed-off-by: Joaquin Anton <janton@nvidia.com>
for (int sample_idx = 0; sample_idx < num_samples; sample_idx++) {
const auto &prospective_crop = sample_data_[sample_idx].prospective_crop;
auto extent = prospective_crop.crop.extent();
auto anchor_out_view = view<float>(anchor_out[sample_idx]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Get a view to whole anchor/shape TLV outside the loop?

auto &bbox_out = ws.template OutputRef<CPUBackend>(2);
bbox_out.Resize(bbox_out_shape);
for (int sample_idx = 0; sample_idx < num_samples; sample_idx++) {
auto bbox_out_view = view<float>(bbox_out[sample_idx]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise - get a view outside of the loop?

Comment on lines 573 to 574
auto labels_in_view = view<const int>(labels_in[sample_idx]);
auto labels_out_view = view<int>(labels_out[sample_idx]);
Copy link
Contributor

Choose a reason for hiding this comment

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

...and again.

}
bbox_indices_out.Resize(bbox_indices_out_shape);
for (int sample_idx = 0; sample_idx < num_samples; sample_idx++) {
auto bbox_indices_out_view = view<int>(bbox_indices_out[sample_idx]);
Copy link
Contributor

Choose a reason for hiding this comment

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

...and once more.

for (int sample_idx = 0; sample_idx < num_samples; sample_idx++) {
auto &data = sample_data_[sample_idx];
tp.AddWork([&, sample_idx](int thread_id) {
auto in_boxes_view = view<const float>(in_boxes[sample_idx]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Get a view to entire batch outside of the loop.

Signed-off-by: Joaquin Anton <janton@nvidia.com>
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1717854]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1717854]: BUILD FAILED

@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1719715]: BUILD STARTED

Signed-off-by: Joaquin Anton <janton@nvidia.com>
@jantonguirao
Copy link
Contributor Author

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1719811]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [1719811]: BUILD PASSED

@jantonguirao jantonguirao merged commit 2df1b24 into NVIDIA:master Oct 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants