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

HSV manipulation operator for GPU & CPU #1338

Merged
merged 149 commits into from
Oct 11, 2019
Merged

HSV manipulation operator for GPU & CPU #1338

merged 149 commits into from
Oct 11, 2019

Conversation

szalpal
Copy link
Member

@szalpal szalpal commented Oct 4, 2019

Why we need this PR?

Pick one

  • This is a HSV manipulation operator both for CPU and GPU. If you find this PR too big, I can split it in 2 parts.
  • What also happened is: I added default values for LinearTransformationGpu kernel (CPU already has them)

Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
}};


inline mat3 compose_hue(float hue /* hue hue hue */ ) {
Copy link
Contributor

@mzient mzient Oct 10, 2019

Choose a reason for hiding this comment

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

srsly?

Copy link
Member Author

Choose a reason for hiding this comment

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

hue hue hue

Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
ret.resize(size);
for (size_t i = 0; i < size; i++) {
ret[i] = Yiq2Rgb * compose_hue(hue[i]) * compose_saturation(saturation[i]) *
compose_value(value[i]) * Rgb2Yiq;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do you insist on having these matrix multiplications here? Especially the perfectly avoidable compose_value (you'd be better off just multiplying by the scalar). And, as I demonstrated before, the function that does all three transforms is not that complicated, either.

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 this is ok from readability standpoint. You define those transformations as rotations/scaling/shifting and compose them into one transformation.

Copy link
Contributor

@mzient mzient Oct 10, 2019

Choose a reason for hiding this comment

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

When we're at readability: how about:

mat3 color_transform = rotate_hue(hue[i]) * scale_saturation(saturation[i]) * scale_value(value[i]);
return Yiq2Rgb * color_transform * Rgb2Yiq;

These compose_xxx names don't really tell us what we do with xxx.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, rotate_hue isn't the best name either, cause it doesn't actually rotate anything.
How about compose_hue_matrix? Or sth shorter:

/**
 * Composes transformation matrix for hue
 */
mat3 hue_mat(){}
[...]

return Yiq2Rgb * hue_mat(hue[i]) * sat_mat(saturation[i]) * val_mat(value[i]) * Rgb2Yiq;

?



template <typename Backend>
class Hsv : public Operator<Backend> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename to HsvOp or something along that line - Hsv is a good name for a structure that contains uint8_t h, s, v or a simple conversion function, but doesn't quite cut it for a full-blown operator.

explicit Hsv(const OpSpec &spec) :
Operator<Backend>(spec),
output_type_(spec.GetArgument<DALIDataType>(hsv::kOutputType)) {
GetSingleOrRepeatedArg(spec, hue_, hsv::kHue, batch_size_);
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 bad. The arguments are not meant to be vectors, they should be either scalars or tensors.

Copy link
Contributor

@mzient mzient left a comment

Choose a reason for hiding this comment

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

Still missing support for dynamic per-sample values.

@szalpal
Copy link
Member Author

szalpal commented Oct 10, 2019

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [940207]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [940207]: BUILD FAILED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [940717]: BUILD STARTED

Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
Signed-off-by: Michał Szołucha <mszolucha@nvidia.com>
@szalpal
Copy link
Member Author

szalpal commented Oct 11, 2019

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [940845]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [940845]: BUILD FAILED

@szalpal
Copy link
Member Author

szalpal commented Oct 11, 2019

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [940953]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [940717]: BUILD PASSED

@szalpal szalpal merged commit abf37ea into NVIDIA:master Oct 11, 2019
@dali-automaton
Copy link
Collaborator

CI MESSAGE: [940953]: BUILD PASSED

@szalpal szalpal deleted the hsv_op branch November 20, 2019 11:19
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

5 participants