Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions modules/dnn/src/layers/concat_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ class ConcatLayerImpl CV_FINAL : public ConcatLayer
ranges[cAxis].start = 0;
for (size_t i = 0; i < inputs.size(); i++)
{
if (inputs[i].empty())
continue;
ranges[cAxis].end = ranges[cAxis].start + inputs[i].size[cAxis];
for (int j = 0; j < outMat.dims; ++j)
{
Expand Down
14 changes: 9 additions & 5 deletions modules/dnn/src/layers/slice_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ Range normalizeRange(const Range& input_range, int n)
{
Range range = input_range;

range.start = std::min(std::max(range.start, -n), n - 1);
if (range.start < 0)
{
range.start += n;
if (!(range.start == n)){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (range.start != n)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If range.start == n doe it mean uninitialized value?

Copy link
Contributor Author

@Abdurrahheem Abdurrahheem Jul 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, it means that start index is equal to the last dimention of the input, in which case we do not want it to be (n-1)

range.start = std::min(std::max(range.start, -n), n - 1);
if (range.start < 0)
{
range.start += n;
}
}

range.end = std::min(std::max(range.end, -n), n);
Expand Down Expand Up @@ -632,7 +634,9 @@ class SliceLayerImpl : public SliceLayer
{
for (size_t i = 0; i < outputs.size(); i++)
{
inpMat(finalSliceRanges[i]).copyTo(outputs[i]);
if (finalSliceRanges[i][0].start != finalSliceRanges[i][0].end){
inpMat(finalSliceRanges[i]).copyTo(outputs[i]);
}
}
}
else
Expand Down
7 changes: 7 additions & 0 deletions modules/dnn/test/test_onnx_importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3099,6 +3099,13 @@ TEST_P(Test_ONNX_layers, Attention) {
TEST_P(Test_ONNX_layers, AttentionSingleHead) {
testONNXModels("attention_single_head");
}
TEST_P(Test_ONNX_layers, TorchAttentionSingleHead){
testONNXModels("torch_attention_single_head");
}

TEST_P(Test_ONNX_layers, TorchUnflatten){
testONNXModels("unflatten");
}

TEST_P(Test_ONNX_nets, ViT_B_32) {
applyTestTag(CV_TEST_TAG_LONG, CV_TEST_TAG_DEBUG_LONG);
Expand Down