LSTM ONNX Layout Attribute Support #23614
Merged
asmorkalov merged 7 commits intoopencv:4.xfrom May 17, 2023
Merged
Conversation
2d9641a to
7025e65
Compare
Contributor
|
@fengyuentau @dkurt Could you look at it? |
dkurt
reviewed
May 17, 2023
dkurt
reviewed
May 17, 2023
dkurt
reviewed
May 17, 2023
| bool need_yc = lstm_proto.output_size() > 2 && !lstm_proto.output(2).empty(); | ||
| bool need_yh = lstm_proto.output_size() > 1 && !lstm_proto.output(1).empty(); | ||
| bool need_y = lstm_proto.output_size() > 0 && !lstm_proto.output(0).empty(); | ||
| bool need_y = lstm_proto.output_size() > 0 && !lstm_proto.output(0).empty(); |
Contributor
Author
There was a problem hiding this comment.
Done! But why?
Member
There was a problem hiding this comment.
Just simpler for the future tracking of changed lines.
dkurt
reviewed
May 17, 2023
dkurt
reviewed
May 17, 2023
dkurt
requested changes
May 17, 2023
Member
dkurt
left a comment
There was a problem hiding this comment.
Please see comments. The main one is to introduce internal enum for different LSTM layouts (sequence, batch) instead of a boolean flag.
dkurt
reviewed
May 17, 2023
dkurt
reviewed
May 17, 2023
dkurt
reviewed
May 17, 2023
dkurt
reviewed
May 17, 2023
dkurt
approved these changes
May 17, 2023
Merged
thewoz
pushed a commit
to thewoz/opencv
that referenced
this pull request
Jan 4, 2024
LSTM ONNX Layout Attribute Support opencv#23614 ### Explanation This PR contains necessary changes to support `layout` attribute. This attributes is present in [ONNX](https://github.com/onnx/onnx/blob/main/docs/Operators.md#lstm) and [Torch](https://pytorch.org/docs/stable/generated/torch.nn.LSTM.html#lstm) (in touch it is name as `batch_first=True`) libraries. When `layout = 1` input to LSTM layer is expected to have batch dimension first -> `[batch_size, sequence_length, features]` vs `layout = 0` - default `[sequence_length, batch_size, features]` ### Test Data Test data and data generator for PR located here [opencv#1063](opencv/opencv_extra#1063) ### 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 - [ ] There is a reference to the original bug report and related work - [x] 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
LSTM ONNX Layout Attribute Support opencv#23614 ### Explanation This PR contains necessary changes to support `layout` attribute. This attributes is present in [ONNX](https://github.com/onnx/onnx/blob/main/docs/Operators.md#lstm) and [Torch](https://pytorch.org/docs/stable/generated/torch.nn.LSTM.html#lstm) (in touch it is name as `batch_first=True`) libraries. When `layout = 1` input to LSTM layer is expected to have batch dimension first -> `[batch_size, sequence_length, features]` vs `layout = 0` - default `[sequence_length, batch_size, features]` ### Test Data Test data and data generator for PR located here [opencv#1063](opencv/opencv_extra#1063) ### 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 - [ ] There is a reference to the original bug report and related work - [x] 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
This PR contains necessary changes to support
layoutattribute. This attributes is present in ONNX and Torch (in touch it is name asbatch_first=True) libraries. Whenlayout = 1input to LSTM layer is expected to have batch dimension first ->[batch_size, sequence_length, features]vslayout = 0- default[sequence_length, batch_size, features]resolves #23602
Test Data
Test data and data generator for PR located here #1063
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.