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

Add debayer operator #4495

Merged
merged 8 commits into from
Dec 7, 2022
Merged

Add debayer operator #4495

merged 8 commits into from
Dec 7, 2022

Conversation

stiepan
Copy link
Member

@stiepan stiepan commented Dec 5, 2022

Add debayer operator
Signed-off-by: Kamil Tokarski ktokarski@nvidia.com

Category:

New feature (non-breaking change which adds functionality)

Description:

  • Adds a new operator based on the npp_debayer_kernel
  • Operator accepts gpu input (bayered images/videos), the algorithm and one of four possible bayer patterns.
  • The only supported algorithm as for now is "bilinear_npp". It is not simply bilinear, because npp does extra "chroma correlation" when inferring green values for blue and red based pixels. I imagine, in the future we may support both: bilinear and bilinear_npp.
  • The bayer pattern specification can be done per-sample and per-frame. For this reason, following @mzient suggestion, the pattern is specified through "blue_position" parameter as 2d coordinate of the blue color within bayer 2x2 tile. It is unambigious although a bit weird. However, support for tensor strings is almost non-existent, while using enums is also a bit akward as it requires reinterperet operator along the way.

Additional information:

Affected modules and functionalities:

  • New operator, new python tests. Existing funcionalities are unaffected.

Key points relevant for the review:

Around 70% of this PR are tests and documentation. It is a small PR. :)

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: DEBAYER.02, 03, 04, 07, 08, 09, 11, 12, 13.

JIRA TASK: DALI-3075

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>

Add docs

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>

NPP baseline tests

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>

Fix lint issues

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>

Better algorithm description in the docs

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>

Revert formatting in npp helper filer

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>

Add debayer calls to stub generator

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>

Include uin16_t tests

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>

Test single-channel 3dim inputs, adjust error messages, prepare seq baseline

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>

Read video helper

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>

Use pair of ints instead of enum, add cpp tests

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>

Simplfy the tests sligthly

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
@stiepan
Copy link
Member Author

stiepan commented Dec 5, 2022

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [6685417]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [6685417]: BUILD FAILED

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
@stiepan
Copy link
Member Author

stiepan commented Dec 6, 2022

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [6692025]: BUILD STARTED

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
@stiepan
Copy link
Member Author

stiepan commented Dec 6, 2022

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [6694079]: BUILD STARTED

Copy link
Contributor

@klecki klecki left a comment

Choose a reason for hiding this comment

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

Still reading tests, comments for implementation

Comment on lines 35 to 36
constexpr static const char *algArgName = "algorithm";
constexpr static const char *bluePosArgName = "blue_position";
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
constexpr static const char *algArgName = "algorithm";
constexpr static const char *bluePosArgName = "blue_position";
constexpr static const char *kAlgArgName = "algorithm";
constexpr static const char *kBluePosArgName = "blue_position";

I think this k is required by the coding guide. I am also never sure if it's better to use those constants or maybe just stick with strings. I was thinking about alternative once, but didn't find anything that would allow to have both validation and not introduce need for additional definitions or obfuscation.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Comment on lines +54 to +57
sample_idx, " has shape ", input_shapes[sample_idx],
", which, assuming HWC layout, implies ", num_channels, " channels. ",
"If you are trying to process video or sequences, please make sure to set "
"input's layout to `FHW`. You can use `fn.reshape` to set proper layout."));
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we do it without assumptions, just check what is the layout and error out accordingly?

Btw, can we access the original layout in Sequence Operator?

Copy link
Member Author

@stiepan stiepan Dec 6, 2022

Choose a reason for hiding this comment

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

If you don't provide any layout but pass 3d tensor in hope of processing sequence of bayered images, you likely will fail here. This is for such a situation. There layout won't tell us much.

Copy link
Member Author

Choose a reason for hiding this comment

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

As to the SequenceOperator, kind of. You have original layouts in ShouldExpand(ws) overrides, the idea was that if you'd like to report layout to the user, you can do that there and then forget about it. There is also IsExpanding() method to tell if that's the sequence case or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, this kinda boils down to the fact, that we don't know if we were running with empty layout if executor set it to a default.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah

blue_position.size(), " values."));
int y = blue_position[0];
int x = blue_position[1];
int bayer_enum_val = 2 * y + x;
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, (-2, 4) would work fine.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, the current check is a bit liberal, just to prevent "overflowing" the enum. Do you think we need the strict version to check it elementwise?

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 so, it's easier to go in the other direction later.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

pattern_.resize(batch_size, static_pattern_);
} else {
const auto &tv = ws.ArgumentInput(debayer::bluePosArgName);
auto blue_positions_view = view<const int, 1>(tv);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just checking, I think we have something that asserts dimensionality here, so it would error out with a bit of a cryptic message, if the user provides us with for example 2D-input. And we don't strictly require 1D data, just two elements exactly?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, we require two elements. And the message will be cryptic. So your suggestion is to go with dynamic extent and simply .num_elements() == 2?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is one solution if you want to be more flexible.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [6692025]: BUILD FAILED

…equiresemnts for the tensor input

Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
Signed-off-by: Kamil Tokarski <ktokarski@nvidia.com>
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [6694079]: BUILD PASSED

@stiepan
Copy link
Member Author

stiepan commented Dec 7, 2022

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [6704750]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [6704750]: BUILD PASSED

return view<const InOutT, 2>(input);
}
assert(([&]() {
for (int sample_idx = 0; sample_idx < in_shape.num_samples(); sample_idx++) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

assert(std::all_of(in_shape.begin(), in_shape.end(), [](auto &shape) { return shape[2] == 1; }));

nitpick

Copy link
Member Author

Choose a reason for hiding this comment

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

Unfortunately, AFAIK, there is no begin/end in neither TL nor TLS class.

@stiepan stiepan merged commit 80ee597 into NVIDIA:main Dec 7, 2022
@JanuszL JanuszL mentioned this pull request Jan 11, 2023
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.

5 participants