-
-
Notifications
You must be signed in to change notification settings - Fork 55.8k
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
G-API: Add transpose operation #20107
Conversation
@@ -575,6 +575,12 @@ namespace core { | |||
return std::make_tuple(empty_gopaque_desc(), empty_array_desc(), empty_array_desc()); | |||
} | |||
}; | |||
|
|||
G_TYPED_KERNEL(GTranspose, <GMat(GMat)>, "org.opencv.core.transpose") { |
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.
Should it be 'org.opencv.core.matrixop.transpose' or 'org.opencv.core.transform.transpose' ?
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 believe the string name is correct as it is not used elsewhere;
What I'd recommend to use is G_API_OP
instead of the G_TYPED_KERNEL
.
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.
(...yes our code uses the old macro almost everywhere)
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.
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.
Shall i rename all old-styled names in this file additionally?
std::tie(cmpF, sz_in, type, compile_args) = GetParam(); | ||
|
||
initMatrixRandU(type, sz_in, type, false); | ||
cv::Mat out_transpose_gapi, out_transpose_ocv; |
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.
There is out_mat_gapi
and out_mat_ocv
already
I think you cold use it instead out_transpose_gapi
and out_transpose_ocv
next time
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.
+1
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.
ok, thanks
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.
Good!
@@ -542,6 +542,7 @@ struct TestWithParamsSpecific : public TestWithParamsBase<ParamsSpecific<Specifi | |||
* @param ... list of names of user-defined parameters. if there are no parameters, the list | |||
* must be empty. | |||
*/ | |||
//TODO: Consider to remove `Number` and use `std::tuple_size<decltype(std::make_tuple(__VA_ARGS__))>::value` |
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.
@andrey-golubev any thoughts on this? :)
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.
oh, looking at it in a silo, that would actually be nice. std::make_tuple
is constexpr since C++14 though (is OpenCV on it already?), so in C++11 that won't help.
there's BOOST_PP_VARIADIC_SIZE
by the way (which is surprisingly interesting) that gives size(__VA_ARGS__
) during preprocessing and might help here as well (but I don't remember this code anymore).
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.
oh, i missed that tuple is constexpr in C++14
@andrey-golubev What do you think about the follow home-grown solution?
#include <iostream>
#include <string>
template<class ...T>
constexpr size_t args_count(T&&...args)
{
return sizeof...(args);
}
#define VAARG_NUM(...) args_count(__VA_ARGS__)
int main(int argc, char **argv)
{
int a,b;
double d;
char c;
std::string str;
struct Foo {};
static_assert(VAARG_NUM() == 0, "Args pack 0 failed, expected 0");
static_assert(VAARG_NUM(str) == 1, "Args pack 1 failed, expected 1");
static_assert(VAARG_NUM(a,b,d,c,str) == 5, "Args pack 2 failed, expected 5");
static_assert(VAARG_NUM(1, "c", 1.0,Foo {}) == 4, "Args pack 3 failed, expected 4");
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.
it depends on whether __VA_ARGS__
are variables or types (which is also a problem with std::make_tuple() I think). you'd need a type function in the latter case.
also note that the logic is to "##" the number to a macro, so that it becomes a new macro name e.g.:
Number = 0: use DEFINE_SPECIFIC_PARAMS_0
Number = 5: use DEFINE_SPECIFIC_PARAMS_5
if I remember this correctly.
so I don't think you'd be able to pull that off with a (possibly-a-type) function to be honest, since the compiler is invoked after the preprocessor.
anyhow, at least you'd need to wrap existing macro into one more to get the literal before using it, which is of course might also be problematic :)
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.
in theory, the whole thing could be rewritten to only use templates (making macro a no-op), not sure why I didn't go this way. there was something about declaring member variables which couldn't be done with a simple template magic (maybe with a complicated magic, but it seemed too much at the time probably).
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.
it depends on whether VA_ARGS are variables or types
I think I understand your point: yes - my home-grown function implementation is for variables only, to cover the types we need another solution. But implementation of generic solution (both for types & variables) requires a lot of effort in decomposition sub-problems for types and variables in single overwhelmed entity.
but for this specific case we receives variables only (for checking fixture correctness), and looks like it is enough to work over __VA_ARGS__
as variables here
Sorry, if i understood you in a wrong way
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 I look at it more and more, seems like __VA_ARGS__
are actually names of to-be-later-created-variables.
you can look at what DEFINE_SPECIFIC_PARAMS does to get the idea.
anyhow, if you figure out a nice way to simplify this, by all means feel free to update this code.
@@ -575,6 +575,12 @@ namespace core { | |||
return std::make_tuple(empty_gopaque_desc(), empty_array_desc(), empty_array_desc()); | |||
} | |||
}; | |||
|
|||
G_TYPED_KERNEL(GTranspose, <GMat(GMat)>, "org.opencv.core.transpose") { |
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 believe the string name is correct as it is not used elsewhere;
What I'd recommend to use is G_API_OP
instead of the G_TYPED_KERNEL
.
@@ -575,6 +575,12 @@ namespace core { | |||
return std::make_tuple(empty_gopaque_desc(), empty_array_desc(), empty_array_desc()); | |||
} | |||
}; | |||
|
|||
G_TYPED_KERNEL(GTranspose, <GMat(GMat)>, "org.opencv.core.transpose") { |
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.
(...yes our code uses the old macro almost everywhere)
std::tie(cmpF, sz_in, type, compile_args) = GetParam(); | ||
|
||
initMatrixRandU(type, sz_in, type, false); | ||
cv::Mat out_transpose_gapi, out_transpose_ocv; |
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.
+1
INSTANTIATE_TEST_CASE_P(TransposePerfTestCPU, TransposePerfTest, | ||
Combine(Values(AbsExact().to_compare_f()), | ||
Values(szSmall128, szVGA, sz720p, sz1080p), | ||
Values(CV_8UC1, CV_16UC1, CV_16SC1, CV_32FC1), |
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.
Are three-channel images supported? I believe it is the case for MTCNN (BGR), @dbudniko please correct me.
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 i'll check it
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've added additional types to param set and it still works OK
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.
LGTM!
@alalek |
G-API: Add transpose operation * Add kernels decl & def * Add draft for UT * Fix UT for Transpose * Add perf test * Fix docs * Apply comments
Add
transpose
operation to gapi which is similar with opencvtranspose
https://docs.opencv.org/master/d2/de8/group__core__array.html#ga46630ed6c0ea6254a35f447289bd7404Add Unit/Perf test
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.