-
-
Notifications
You must be signed in to change notification settings - Fork 56.4k
Ellipses supported added for Einsum Layer #24322
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
Conversation
|
|
@Abdurrahheem Thanks a lot for the patch! The PR adds 2 features, but only one test. Could you cover both? |
| for (int slice = 0; slice < total_slices; ++slice) { | ||
| for (int j = 0; j < inner_stride; ++j) { | ||
| // Extract diagonal elements | ||
| output.at<T>(slice, j, 0) = input.at<T>(slice, j, j); |
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.
Looks like the 3rd dimension is redundant. You can create output mat with 2 dimensions and drop reshape at the end.
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.
tested suggestion. This breaks the the tests. Let's leave as it is maybe? since the suggestion only reduces one reshape operation
|
@dkurt @fengyuentau Please take a look again. |
| } | ||
|
|
||
| // Reshape output back to original shape | ||
| original_dims[rank - 1] = 1; // Set the last dimension to 1, as we have extracted the diagonal |
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.
Why not initialize output with the final dimensions once but int the loop work with a data pointer?
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.
changed. now without reshape
| for (int slice = 0; slice < total_slices; ++slice) { | ||
| for (int j = 0; j < inner_stride; ++j) { | ||
| // Extract diagonal elements | ||
| output.at<T>(slice, j, 0) = input.at<T>(slice, j, j); |
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.
This method can be without template by using cv::Mat::diag:
input = input(1, total_slices);
output = output.reshape(1, total_slices);
for (int slice = 0; slice < total_slices; ++slice) {
Mat src = input.row(slice).reshape(1, inner_stride).diag(0);
Mat dst = output.row(slice);
src.copyTo(dst);
}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.
tested, this introduces regression in accuracy
|
|
||
| if (output_dims != shape(output)){ | ||
| CV_Error(Error::StsError, "Output shape does not match with calculated 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.
Do we really need output_dims as it's used only for the check?
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.
do we not need to check?
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.
We probably initialize output somewhere once in the code with such shapes.
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.
output shape for this particular function is not saved anywhere. However, overall output shape is save, of course. Because of this I need to check the outputs for compatibility.
|
@dkurt please take a look again. |
Test case for Einsum ellipse functionality #1106 This PR contains test case for Einsum Ellipses addition patch [#24322](opencv/opencv#24322)
Ellipses supported added for Einsum Layer opencv#24322 This PR added addresses issues not covered in opencv#24037. Namely these are: Test case for this patch is in this PR [opencv#1106](opencv/opencv_extra#1106) in opencv extra Added: - [x] Broadcasting reduction "...ii ->...I" - [x] Add lazy shape deduction. "...ij, ...jk->...ik" Features to add: - [ ] Add implicit output computation support. "bij,bjk ->" (output subscripts should be "bik") - [ ] Add support for CUDA backend - [ ] BatchWiseMultiply optimize - [ ] Performance test ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
Ellipses supported added for Einsum Layer opencv#24322 This PR added addresses issues not covered in opencv#24037. Namely these are: Test case for this patch is in this PR [opencv#1106](opencv/opencv_extra#1106) in opencv extra Added: - [x] Broadcasting reduction "...ii ->...I" - [x] Add lazy shape deduction. "...ij, ...jk->...ik" Features to add: - [ ] Add implicit output computation support. "bij,bjk ->" (output subscripts should be "bik") - [ ] Add support for CUDA backend - [ ] BatchWiseMultiply optimize - [ ] Performance test ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
Ellipses supported added for Einsum Layer opencv#24322 This PR added addresses issues not covered in opencv#24037. Namely these are: Test case for this patch is in this PR [opencv#1106](opencv/opencv_extra#1106) in opencv extra Added: - [x] Broadcasting reduction "...ii ->...I" - [x] Add lazy shape deduction. "...ij, ...jk->...ik" Features to add: - [ ] Add implicit output computation support. "bij,bjk ->" (output subscripts should be "bik") - [ ] Add support for CUDA backend - [ ] BatchWiseMultiply optimize - [ ] Performance test ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [x] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This PR added addresses issues not covered in #24037. Namely these are:
Test case for this patch is in this PR #1106 in opencv extra
Added:
Features to add:
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.