Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv_contrib
Commits
0b4fc061
Commit
0b4fc061
authored
Jun 19, 2017
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1234 from dkurt:fix_reshape_layer
parents
aa0d8060
12b17910
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
10 deletions
+36
-10
reshape_layer.cpp
modules/dnn/src/layers/reshape_layer.cpp
+8
-2
test_layers.cpp
modules/dnn/test/test_layers.cpp
+28
-8
No files found.
modules/dnn/src/layers/reshape_layer.cpp
View file @
0b4fc061
...
...
@@ -55,7 +55,6 @@ static void computeShapeByReshapeMask(const MatShape &srcShape,
{
int
srcShapeSize
=
(
int
)
srcShape
.
size
();
int
maskShapeSize
=
(
int
)
maskShape
.
size
();
int
maskTotal
=
abs
(
total
(
maskShape
));
// Mask might have negative ones.
if
(
srcRange
==
Range
::
all
())
srcRange
=
Range
(
0
,
srcShapeSize
);
...
...
@@ -66,8 +65,15 @@ static void computeShapeByReshapeMask(const MatShape &srcShape,
srcRange
.
end
=
srcRange
.
end
==
INT_MAX
?
srcShapeSize
:
srcRange
.
start
+
sz
;
}
if
(
maskTotal
!=
0
)
bool
explicitMask
=
!
maskShape
.
empty
();
// All mask values are positive.
for
(
int
i
=
0
,
n
=
maskShape
.
size
();
i
<
n
&&
explicitMask
;
++
i
)
{
explicitMask
=
maskShape
[
i
]
>
0
;
}
// Working range of source shape is a range where area(src) == area(mask).
if
(
explicitMask
)
{
int
maskTotal
=
total
(
maskShape
);
for
(
int
i
=
srcRange
.
start
+
1
;
i
<
srcRange
.
end
;
++
i
)
{
if
(
total
(
srcShape
,
i
,
srcRange
.
end
)
!=
maskTotal
)
...
...
modules/dnn/test/test_layers.cpp
View file @
0b4fc061
...
...
@@ -169,14 +169,20 @@ TEST(Layer_Test_MVN, Accuracy)
testLayerUsingCaffeModels
(
"layer_mvn"
);
}
TEST
(
Layer_Test_Reshape
,
squeeze
)
void
testReshape
(
const
MatShape
&
inputShape
,
const
MatShape
&
targetShape
,
int
axis
=
0
,
int
num_axes
=
-
1
,
bool
reorder_dims
=
false
,
MatShape
mask
=
MatShape
())
{
LayerParams
params
;
params
.
set
(
"axis"
,
2
);
params
.
set
(
"num_axes"
,
1
);
params
.
set
(
"axis"
,
axis
);
params
.
set
(
"num_axes"
,
num_axes
);
params
.
set
(
"reorder_dims"
,
reorder_dims
);
if
(
!
mask
.
empty
())
{
params
.
set
(
"dim"
,
DictValue
::
arrayInt
<
int
*>
(
&
mask
[
0
],
mask
.
size
()));
}
int
sz
[]
=
{
4
,
3
,
1
,
2
};
Mat
inp
(
4
,
sz
,
CV_32F
);
Mat
inp
(
inputShape
.
size
(),
&
inputShape
[
0
],
CV_32F
);
std
::
vector
<
Mat
>
inpVec
(
1
,
inp
);
std
::
vector
<
Mat
>
outVec
,
intVec
;
...
...
@@ -185,9 +191,23 @@ TEST(Layer_Test_Reshape, squeeze)
Mat
&
out
=
outVec
[
0
];
MatShape
shape
(
out
.
size
.
p
,
out
.
size
.
p
+
out
.
dims
);
int
sh0
[]
=
{
4
,
3
,
2
};
MatShape
shape0
(
sh0
,
sh0
+
3
);
EXPECT_EQ
(
shape
,
shape0
);
EXPECT_EQ
(
shape
,
targetShape
);
}
TEST
(
Layer_Test_Reshape
,
Accuracy
)
{
{
int
inp
[]
=
{
4
,
3
,
1
,
2
};
int
out
[]
=
{
4
,
3
,
2
};
testReshape
(
MatShape
(
inp
,
inp
+
4
),
MatShape
(
out
,
out
+
3
),
2
,
1
);
}
{
int
inp
[]
=
{
1
,
128
,
4
,
4
};
int
out
[]
=
{
1
,
2048
};
int
mask
[]
=
{
-
1
,
2048
};
testReshape
(
MatShape
(
inp
,
inp
+
4
),
MatShape
(
out
,
out
+
2
),
0
,
-
1
,
true
,
MatShape
(
mask
,
mask
+
2
));
}
}
TEST
(
Layer_Test_BatchNorm
,
Accuracy
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment