-
Notifications
You must be signed in to change notification settings - Fork 611
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 Translate affine transform generator #2297
Add Translate affine transform generator #2297
Conversation
979a812
to
dbf58f8
Compare
|
||
template <typename T> | ||
void RunImplTyped(workspace_t<Backend> &ws, dims<>) { | ||
DALI_FAIL(make_string("Unsupported number of dimensions ", ndim_)); // NOLINT |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DALI_FAIL(make_string("Unsupported number of dimensions ", ndim_)); // NOLINT | |
DALI_FAIL(make_string("Unsupported number of dimensions ", ndim_)); |
leftover from VALUE_SWITCH, I guess...
for (int i = 0; i < nsamples_; i++) { | ||
DALI_ENFORCE(shape[i] == shape[0], | ||
make_string("Samples are expected to have the same dimensionality. Got: ", shape)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for (int i = 0; i < nsamples_; i++) { | |
DALI_ENFORCE(shape[i] == shape[0], | |
make_string("Samples are expected to have the same dimensionality. Got: ", shape)); | |
} | |
DALI_ENFORCE(is_uniform(shape), "All matrices must have the same shape."); |
...and I'd move this check higher.
} else { | ||
assert(ndim == offset_.size()); | ||
auto &matrix = matrices[0]; | ||
matrix = affine_mat_t<T, ndim>::identity(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
matrix = affine_mat_t<T, ndim>::identity(); | |
matrix = 1; |
much shorter :)
} | ||
} else { | ||
assert(ndim == offset_.size()); | ||
auto &matrix = matrices[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Either do it once or query for offset argument each time. Now you keep rewriting the matrices with a value that can't change at run-time.
|
||
DALI_SCHEMA(TranslateTransform) | ||
.DocStr(R"(TranslateTransform)") | ||
.AddArg("offset", "Translation vector", DALI_FLOAT_VEC, true) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we should rename it to "T" to aligned with CoordTransform
.AddArg("offset", "Translation vector", DALI_FLOAT_VEC, true) | |
.AddArg("T", "Translation vector", DALI_FLOAT_VEC, true) |
} | ||
|
||
auto &out = ws.template OutputRef<Backend>(0); | ||
out.SetLayout(""); // TODO(janton): Decide what layout we want for transforms |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can live with no layout for plain matrices - unless we want to somehow stress that they're row-major - then maybe "rc" (row col).
const TransformImpl &This() const noexcept { return static_cast<const TransformImpl&>(*this); } | ||
|
||
protected: | ||
void CheckInputDimensionality(const workspace_t<CPUBackend> &ws) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd avoid the name "dimensionality" - especially as a standalone word. Here I'd use
void CheckInputDimensionality(const workspace_t<CPUBackend> &ws) { | |
void CheckInputShape(const workspace_t<CPUBackend> &ws) { |
"Unexpected number of dimensions: expected ", ndim_, | ||
" dimensions but the input transform has ", in_t_ndim)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Unexpected number of dimensions: expected ", ndim_, | |
" dimensions but the input transform has ", in_t_ndim)); | |
"The input describes a ", in_t_dim, "D transform but other arguments suggest a ", | |
ndim_, "D transform")); |
int nsamples_ = -1; | ||
bool has_input_ = false; | ||
|
||
std::vector<uint8_t> matrices_data_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grammar Nazi to the rescue:
std::vector<uint8_t> matrices_data_; | |
std::vector<uint8_t> matrix_data_; |
or, if you insist on plural:
std::vector<uint8_t> matrices_data_; | |
std::vector<uint8_t> raw_matrices_; |
BTW - if you're type-punning these, why not a Tensor?
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
8a27256
to
d0ecae9
Compare
Signed-off-by: Joaquin Anton <janton@nvidia.com>
Signed-off-by: Joaquin Anton <janton@nvidia.com>
a596f6f
to
635815b
Compare
#include "dali/pipeline/data/views.h" | ||
|
||
namespace dali { | ||
|
||
DALI_SCHEMA(TranslateTransform) | ||
.DocStr(R"(TranslateTransform)") | ||
.AddArg("offset", "Translation vector", DALI_FLOAT_VEC, true) | ||
.DocStr(R"(Produces a translation affine transform. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.DocStr(R"(Produces a translation affine transform. | |
.DocStr(R"(Produces a translation affine transform matrix. |
.AddArg("offset", "Translation vector", DALI_FLOAT_VEC, true) | ||
.DocStr(R"(Produces a translation affine transform. | ||
|
||
If another transform is passed as an input, the operator will combine the two transforms by applying |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If another transform is passed as an input, the operator will combine the two transforms by applying | |
If another transform matrix is passed as an input, the operator will combine the two matrices by applying |
translation to the transform provided. | ||
|
||
.. note:: | ||
The output of this operator can be fed directly to ``MT`` argument of ``CoordTransform`` operator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use it in Warp operator for images as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As far as I know, WarpAffine operator expects the inverse of the transform, so it can't be directly fed into it until WarpAffine implements the flag to accept inverse transforms. @mzient Correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For translation, we'd just need to use the negated translation vector. Or, if you don't have point cloud to go with your image, you can construct the dst-to-src transform directly.
)") | ||
.AddArg( | ||
"offset", | ||
"Translation vector. The number of dimensions of the transform is inferred from this argument", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Translation vector. The number of dimensions of the transform is inferred from this argument", | |
R"code(Translation vector. | |
The number of dimensions of the transform is inferred from this argument)code", |
a86b681
to
0e8b347
Compare
0e8b347
to
6555902
Compare
adf06b9
to
ecc3501
Compare
Signed-off-by: Joaquin Anton <janton@nvidia.com>
ecc3501
to
c15cebe
Compare
0566de4
to
d7a6c63
Compare
Signed-off-by: Joaquin Anton <janton@nvidia.com>
d7a6c63
to
1a505c2
Compare
!build |
CI MESSAGE: [1662998]: BUILD STARTED |
CI MESSAGE: [1662998]: BUILD FAILED |
Signed-off-by: Joaquin Anton <janton@nvidia.com>
CI MESSAGE: [1663069]: BUILD STARTED |
CI MESSAGE: [1663069]: BUILD FAILED |
Signed-off-by: Joaquin Anton <janton@nvidia.com>
CI MESSAGE: [1663137]: BUILD STARTED |
CI MESSAGE: [1663137]: BUILD FAILED |
CI MESSAGE: [1663137]: BUILD PASSED |
Signed-off-by: Joaquin Anton janton@nvidia.com
Why we need this PR?
What happened in this PR?
Fill relevant points, put NA otherwise. Replace anything inside []
Introduced a TransformBaseOp that defines most of the logic necessary to implement the different transformations. TransformBaseOp uses the curiously recurring template pattern (CRTP)
Added the implementation of TranslateTransform, including tests
New operator
TransformBaseOp and TranslateTransform
Python tests added
Doc str
JIRA TASK: [DALI-1626]