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
b70a9dc1
Commit
b70a9dc1
authored
Jul 09, 2016
by
Vitaliy Lyudvichenko
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding of templated GPU/CPU implementation of Convolution layer
parent
b26896c0
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
24 additions
and
10 deletions
+24
-10
blob.hpp
modules/dnn/include/opencv2/dnn/blob.hpp
+1
-0
blob.inl.hpp
modules/dnn/include/opencv2/dnn/blob.inl.hpp
+2
-2
convolution_layer.cpp
modules/dnn/src/layers/convolution_layer.cpp
+0
-0
convolution_layer.hpp
modules/dnn/src/layers/convolution_layer.hpp
+7
-2
op_blas.cpp
modules/dnn/src/layers/op_blas.cpp
+13
-6
test_googlenet.cpp
modules/dnn/test/test_googlenet.cpp
+1
-0
No files found.
modules/dnn/include/opencv2/dnn/blob.hpp
View file @
b70a9dc1
...
...
@@ -297,6 +297,7 @@ namespace dnn
mutable
uchar
state
;
#endif
public
:
enum
DataState
{
UNINITIALIZED
,
...
...
modules/dnn/include/opencv2/dnn/blob.inl.hpp
View file @
b70a9dc1
...
...
@@ -346,12 +346,12 @@ inline size_t Blob::offset(int n, int cn, int row, int col) const
inline
float
*
Blob
::
ptrf
(
int
n
,
int
cn
,
int
row
,
int
col
)
{
return
matRef
().
ptr
<
float
>
()
+
offset
(
n
,
cn
,
row
,
col
);
return
matRef
(
false
).
ptr
<
float
>
()
+
offset
(
n
,
cn
,
row
,
col
);
}
inline
uchar
*
Blob
::
ptr
(
int
n
,
int
cn
,
int
row
,
int
col
)
{
Mat
&
mat
=
matRef
();
Mat
&
mat
=
matRef
(
false
);
return
mat
.
ptr
()
+
mat
.
elemSize
()
*
offset
(
n
,
cn
,
row
,
col
);
}
...
...
modules/dnn/src/layers/convolution_layer.cpp
View file @
b70a9dc1
This diff is collapsed.
Click to expand it.
modules/dnn/src/layers/convolution_layer.hpp
View file @
b70a9dc1
...
...
@@ -63,18 +63,23 @@ namespace dnn
int
inpGroupCn
,
outGroupCn
;
int
ksize
;
bool
useOpenCL
;
bool
tryUseOpenCL
,
useOpenCL
;
Blob
colBlob
,
biasOnesBlob
;
Mat
colMat
,
biasOnesMat
;
inline
bool
is1x1
()
const
;
virtual
void
computeInpOutShape
(
const
Blob
&
inpBlob
);
void
im2col
(
Blob
&
inpBlob
,
int
imNum
,
int
cnGroup
);
void
im2col
(
Blob
&
inpBlob
,
int
imNum
,
int
cnGroup
,
Blob
&
colBlob
);
public
:
ConvolutionLayer
()
{}
ConvolutionLayer
(
LayerParams
&
params
);
void
allocate
(
const
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
);
void
forward
(
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
);
template
<
typename
XMat
>
void
forward_
(
std
::
vector
<
Blob
*>
&
inputs
,
std
::
vector
<
Blob
>
&
outputs
);
};
class
DeConvolutionLayer
:
public
ConvolutionLayer
...
...
modules/dnn/src/layers/op_blas.cpp
View file @
b70a9dc1
...
...
@@ -11,9 +11,15 @@ namespace cv
namespace
dnn
{
void
gemm
(
InputArray
A
,
InputArray
B
,
double
alpha
,
InputOutputArray
C
,
double
beta
,
int
flags
/*= 0*/
)
void
gemm
(
InputArray
A
,
InputArray
B
,
double
alpha
,
InputOutputArray
C
,
double
beta
,
int
flags
)
{
cv
::
gemm
(
A
,
B
,
alpha
,
C
,
beta
,
C
,
flags
);
if
(
C
.
isMat
())
gemmCPU
(
A
.
getMat
(),
B
.
getMat
(),
alpha
,
C
.
getMatRef
(),
beta
,
flags
);
else
{
cv
::
gemm
(
A
,
B
,
alpha
,
C
,
beta
,
C
,
flags
);
std
::
cout
<<
"OCL gemm
\n
"
;
}
}
inline
void
SwapRowCols
(
const
Mat
&
A
,
int
&
rows
,
int
&
cols
,
bool
isTrans
)
...
...
@@ -35,10 +41,9 @@ void gemmCPU(const Mat &A, const Mat &B, double alpha, Mat &C, double beta, int
SwapRowCols
(
B
,
Brows
,
Bcols
,
transB
);
SwapRowCols
(
C
,
Crows
,
Ccols
,
transC
);
CV_
Dbg
Assert
(
!
(
flags
&
GEMM_3_T
));
CV_Assert
(
!
(
flags
&
GEMM_3_T
));
CV_Assert
(
Acols
==
Brows
&&
Arows
==
Crows
&&
Bcols
==
Ccols
);
CV_Assert
(
A
.
isContinuous
()
&&
B
.
isContinuous
()
&&
C
.
isContinuous
());
CV_Assert
(
A
.
type
()
==
CV_32F
||
A
.
type
()
==
CV_64F
);
CV_Assert
(
A
.
type
()
==
B
.
type
()
&&
B
.
type
()
==
C
.
type
());
CV_Assert
(
A
.
data
!=
C
.
data
&&
B
.
data
!=
C
.
data
);
...
...
@@ -59,6 +64,10 @@ void gemmCPU(const Mat &A, const Mat &B, double alpha, Mat &C, double beta, int
B
.
ptr
<
double
>
(),
B
.
cols
,
beta
,
C
.
ptr
<
double
>
(),
C
.
cols
);
}
else
{
CV_Error
(
Error
::
BadDepth
,
"Only floating point types are supported"
);
}
#else
cv
::
gemm
(
A
,
B
,
alpha
,
C
,
beta
,
C
,
flags
);
#endif
...
...
@@ -70,7 +79,6 @@ int getBlasThreads()
return
openblas_get_num_threads
();
#else
return
1
;
#endif
}
...
...
@@ -81,7 +89,6 @@ void setBlasThreads(int numThreads)
goto_set_num_threads
(
numThreads
);
#else
(
void
)
numThreads
;
//suppress compilers' warning
numThreads
=
0
;
#endif
}
...
...
modules/dnn/test/test_googlenet.cpp
View file @
b70a9dc1
...
...
@@ -42,6 +42,7 @@
#if defined(ENABLE_CAFFE_MODEL_TESTS)
#include "test_precomp.hpp"
#include "npy_blob.hpp"
#include <opencv2/core/ocl.hpp>
namespace
cvtest
{
...
...
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