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
4f578068
Commit
4f578068
authored
Aug 02, 2016
by
Vitaliy Lyudvichenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixing of reshape and concat layers in OCL mode.
parent
7f0260c1
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
26 deletions
+37
-26
init.cpp
modules/dnn/src/init.cpp
+0
-1
concat_layer.cpp
modules/dnn/src/layers/concat_layer.cpp
+1
-1
elementwise_layers.hpp
modules/dnn/src/layers/elementwise_layers.hpp
+3
-3
reshape_layer.cpp
modules/dnn/src/layers/reshape_layer.cpp
+11
-0
reshape_layer.hpp
modules/dnn/src/layers/reshape_layer.hpp
+2
-1
split_layer.cpp
modules/dnn/src/layers/split_layer.cpp
+1
-1
test_layers.cpp
modules/dnn/test/test_layers.cpp
+19
-19
No files found.
modules/dnn/src/init.cpp
View file @
4f578068
...
...
@@ -42,7 +42,6 @@
#include "precomp.hpp"
#include "caffe/layer_loaders.hpp"
#include "layers/concat_layer.hpp"
#include "layers/blank_layer.hpp"
#include "layers/mvn_layer.hpp"
#include "layers/reshape_layer.hpp"
...
...
modules/dnn/src/layers/concat_layer.cpp
View file @
4f578068
...
...
@@ -80,7 +80,7 @@ void ConcatLayerImpl::allocate(const std::vector<Blob *> &inputs, std::vector<Bl
refShape
[
axisIdx
]
=
axisSum
;
useOpenCL
&=
ocl
::
useOpenCL
();
int
allocFlags
=
(
useOpenCL
)
?
Blob
::
ALLOC_UMAT
:
Blob
::
ALLOC_
U
MAT
;
int
allocFlags
=
(
useOpenCL
)
?
Blob
::
ALLOC_UMAT
:
Blob
::
ALLOC_MAT
;
outputs
.
resize
(
1
);
outputs
[
0
].
create
(
refShape
,
inputs
[
0
]
->
type
(),
allocFlags
);
...
...
modules/dnn/src/layers/elementwise_layers.hpp
View file @
4f578068
...
...
@@ -99,10 +99,10 @@ public:
outputs
[
i
].
shareFrom
(
*
inputs
[
i
]);
//no data copy
//hotfix: shareFrom doesn't provide properly Mat/UMat switching
if
(
!
useOpenCL
)
outputs
[
i
].
matRef
()
=
inputs
[
i
]
->
matRefConst
();
else
if
(
useOpenCL
)
outputs
[
i
].
umatRef
()
=
inputs
[
i
]
->
umatRefConst
();
else
outputs
[
i
].
matRef
()
=
inputs
[
i
]
->
matRefConst
();
}
}
...
...
modules/dnn/src/layers/reshape_layer.cpp
View file @
4f578068
...
...
@@ -84,6 +84,7 @@ ReshapeLayer::ReshapeLayer(LayerParams ¶ms) : Layer(params)
void
ReshapeLayer
::
allocate
(
const
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
)
{
outputs
.
resize
(
inputs
.
size
());
outShapes
.
resize
(
inputs
.
size
());
for
(
size_t
i
=
0
;
i
<
inputs
.
size
();
i
++
)
{
...
...
@@ -100,12 +101,22 @@ void ReshapeLayer::allocate(const std::vector<Blob*> &inputs, std::vector<Blob>
BlobShape
outShape
=
BlobShape
::
all
(
newDims
);
computeOutputShape
(
startAxis
,
endAxis
,
inpShape
,
outShape
);
outShapes
[
i
]
=
outShape
;
outBlob
.
shareFrom
(
inpBlob
);
outBlob
.
reshape
(
outShape
);
}
}
void
ReshapeLayer
::
forward
(
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
)
{
for
(
size_t
i
=
0
;
i
<
outputs
.
size
();
i
++
)
{
outputs
[
i
].
shareFrom
(
*
inputs
[
i
]);
outputs
[
i
].
reshape
(
outShapes
[
i
]);
}
}
void
ReshapeLayer
::
computeOutputShape
(
int
startAxis
,
int
endAxis
,
BlobShape
&
inpShape
,
BlobShape
&
outShape
)
{
int
idx
=
0
;
...
...
modules/dnn/src/layers/reshape_layer.hpp
View file @
4f578068
...
...
@@ -55,10 +55,11 @@ public:
void
allocate
(
const
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
);
void
forward
(
std
::
vector
<
Blob
*>
&
,
std
::
vector
<
Blob
>&
)
{}
void
forward
(
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
);
protected
:
BlobShape
shapeDesc
;
std
::
vector
<
BlobShape
>
outShapes
;
int
inAxis
,
inNumAxes
,
autoAxisIdx
;
void
computeOutputShape
(
int
startAxis
,
int
endAxis
,
BlobShape
&
inpShape
,
BlobShape
&
outShape
);
...
...
modules/dnn/src/layers/split_layer.cpp
View file @
4f578068
...
...
@@ -58,7 +58,7 @@ void SplitLayerImpl::allocate(const std::vector<Blob*> &inputs, std::vector<Blob
{
CV_Assert
(
inputs
.
size
()
==
1
);
useOpenCL
=
ocl
::
useOpenCL
()
&&
inputs
[
0
]
->
getState
()
==
Blob
::
HEAD_AT_UMAT
;
int
allocFlags
=
useOpenCL
?
Blob
::
ALLOC_UMAT
:
Blob
::
ALLOC_
U
MAT
;
int
allocFlags
=
useOpenCL
?
Blob
::
ALLOC_UMAT
:
Blob
::
ALLOC_MAT
;
if
(
outputsCount
>=
0
)
outputs
.
resize
(
outputsCount
);
...
...
modules/dnn/test/test_layers.cpp
View file @
4f578068
...
...
@@ -214,25 +214,25 @@ TEST(Layer_Test_Reshape, squeeze)
EXPECT_EQ
(
outVec
[
0
].
shape
(),
BlobShape
(
4
,
3
,
2
));
}
template
<
typename
XMat
>
static
void
test_Layer_Concat
()
{
Matx21f
a
(
1.
f
,
1.
f
),
b
(
2.
f
,
2.
f
),
c
(
3.
f
,
3.
f
);
std
::
vector
<
Blob
>
res
(
1
),
src
=
{
Blob
(
XMat
(
a
)),
Blob
(
XMat
(
b
)),
Blob
(
XMat
(
c
))
};
Blob
ref
(
XMat
(
Matx23f
(
1.
f
,
2.
f
,
3.
f
,
1.
f
,
2.
f
,
3.
f
)));
runLayer
(
ConcatLayer
::
create
(
1
),
src
,
res
);
normAssert
(
ref
,
res
[
0
]);
}
TEST
(
Layer_Concat
,
Accuracy
)
{
OCL_OFF
(
test_Layer_Concat
<
Mat
>
());
}
OCL_TEST
(
Layer_Concat
,
Accuracy
)
{
OCL_ON
(
test_Layer_Concat
<
Mat
>
());
OCL_OFF
();
}
//
template<typename XMat>
//
static void test_Layer_Concat()
//
{
//
Matx21f a(1.f, 1.f), b(2.f, 2.f), c(3.f, 3.f);
//
std::vector<Blob> res(1), src = { Blob(XMat(a)), Blob(XMat(b)), Blob(XMat(c)) };
//
Blob ref(XMat(Matx23f(1.f, 2.f, 3.f, 1.f, 2.f, 3.f)));
//
//
runLayer(ConcatLayer::create(1), src, res);
//
normAssert(ref, res[0]);
//
}
//
TEST(Layer_Concat, Accuracy)
//
{
//
OCL_OFF(test_Layer_Concat<Mat>());
//
}
//
OCL_TEST(Layer_Concat, Accuracy)
//
{
//
OCL_ON(test_Layer_Concat<Mat>());
//
OCL_OFF();
//
}
template
<
typename
XMat
>
void
test_Reshape_Split_Slice_layers
()
...
...
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