Skip to content

Conversation

@Abdurrahheem
Copy link
Contributor

@Abdurrahheem Abdurrahheem commented Sep 26, 2023

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:

  • Broadcasting reduction "...ii ->...I"
  • 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

  • I agree to contribute to the project under Apache 2 License.
  • 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
  • The PR is proposed to the proper branch
  • 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.
  • The feature is well documented and sample code can be built with the project CMake

@Abdurrahheem Abdurrahheem added the category: dnn (onnx) ONNX suport issues in DNN module label Sep 26, 2023
@Abdurrahheem Abdurrahheem added this to the 4.9.0 milestone Sep 26, 2023
@Abdurrahheem Abdurrahheem self-assigned this Sep 26, 2023
@asmorkalov
Copy link
Contributor

Run cd $HOME/build && python3 $HOME/scripts/warnings-handling.py
/home/ci/opencv/modules/dnn/src/layers/einsum_layer.cpp:1057:68: warning: value computed is not used [-Wunused-value]

@asmorkalov asmorkalov marked this pull request as ready for review October 2, 2023 08:46
@asmorkalov
Copy link
Contributor

@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);
Copy link
Contributor

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.

Copy link
Contributor Author

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

@asmorkalov
Copy link
Contributor

@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
Copy link
Member

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?

Copy link
Contributor Author

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);
Copy link
Member

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);
}

Copy link
Contributor Author

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");
}
Copy link
Member

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?

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

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.

@asmorkalov
Copy link
Contributor

@dkurt please take a look again.

@asmorkalov asmorkalov assigned dkurt and unassigned Abdurrahheem Oct 24, 2023
@asmorkalov asmorkalov merged commit a3b3a58 into opencv:4.x Oct 24, 2023
asmorkalov pushed a commit to opencv/opencv_extra that referenced this pull request Oct 24, 2023
Test case for Einsum ellipse functionality #1106

This PR contains test case for Einsum Ellipses addition patch [#24322](opencv/opencv#24322)
@asmorkalov asmorkalov mentioned this pull request Nov 3, 2023
IskXCr pushed a commit to Haosonn/opencv that referenced this pull request Dec 20, 2023
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
@opencv-alalek opencv-alalek removed their request for review December 26, 2023 20:45
thewoz pushed a commit to thewoz/opencv that referenced this pull request Jan 4, 2024
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
thewoz pushed a commit to thewoz/opencv that referenced this pull request May 29, 2024
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: dnn (onnx) ONNX suport issues in DNN module feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants