Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
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
Commits
5b868ccd
Commit
5b868ccd
authored
Mar 09, 2018
by
Alexander Alekhin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #10992 from dkurt:dnn_opencl_tests
parents
687394fa
0f01b40d
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
95 additions
and
125 deletions
+95
-125
convolution_layer.cpp
modules/dnn/src/layers/convolution_layer.cpp
+3
-0
fully_connected_layer.cpp
modules/dnn/src/layers/fully_connected_layer.cpp
+5
-0
lrn_layer.cpp
modules/dnn/src/layers/lrn_layer.cpp
+5
-0
pooling_layer.cpp
modules/dnn/src/layers/pooling_layer.cpp
+4
-0
softmax_layer.cpp
modules/dnn/src/layers/softmax_layer.cpp
+5
-0
test_backends.cpp
modules/dnn/test/test_backends.cpp
+0
-3
test_caffe_importer.cpp
modules/dnn/test/test_caffe_importer.cpp
+50
-122
test_googlenet.cpp
modules/dnn/test/test_googlenet.cpp
+4
-0
test_precomp.hpp
modules/dnn/test/test_precomp.hpp
+19
-0
test_tf_importer.cpp
modules/dnn/test/test_tf_importer.cpp
+0
-0
test_torch_importer.cpp
modules/dnn/test/test_torch_importer.cpp
+0
-0
No files found.
modules/dnn/src/layers/convolution_layer.cpp
View file @
5b868ccd
...
...
@@ -273,6 +273,9 @@ public:
for
(
int
i
=
0
;
i
<
outCn
;
i
++
)
biasvec
[
i
]
=
biasMat
.
at
<
float
>
(
i
);
}
#ifdef HAVE_OPENCL
convolutionOp
.
release
();
#endif
}
bool
setActivation
(
const
Ptr
<
ActivationLayer
>&
layer
)
...
...
modules/dnn/src/layers/fully_connected_layer.cpp
View file @
5b868ccd
...
...
@@ -267,6 +267,11 @@ public:
};
#ifdef HAVE_OPENCL
void
finalize
(
const
std
::
vector
<
Mat
*>
&
inputs
,
std
::
vector
<
Mat
>
&
outputs
)
{
innerProductOp
.
release
();
}
bool
forward_ocl
(
InputArrayOfArrays
inps
,
OutputArrayOfArrays
outs
,
InputArrayOfArrays
internals
)
{
std
::
vector
<
UMat
>
inputs
;
...
...
modules/dnn/src/layers/lrn_layer.cpp
View file @
5b868ccd
...
...
@@ -96,6 +96,11 @@ public:
}
#ifdef HAVE_OPENCL
void
finalize
(
const
std
::
vector
<
Mat
*>
&
inputs
,
std
::
vector
<
Mat
>
&
outputs
)
{
lrnOp
.
release
();
}
bool
forward_ocl
(
InputArrayOfArrays
inps
,
OutputArrayOfArrays
outs
,
OutputArrayOfArrays
internals
)
{
std
::
vector
<
UMat
>
inputs
;
...
...
modules/dnn/src/layers/pooling_layer.cpp
View file @
5b868ccd
...
...
@@ -127,6 +127,10 @@ public:
}
getConvPoolPaddings
(
inp
,
out
,
kernel
,
stride
,
padMode
,
Size
(
1
,
1
),
pad
);
#ifdef HAVE_OPENCL
poolOp
.
release
();
#endif
}
virtual
bool
supportBackend
(
int
backendId
)
...
...
modules/dnn/src/layers/softmax_layer.cpp
View file @
5b868ccd
...
...
@@ -94,6 +94,11 @@ public:
}
#ifdef HAVE_OPENCL
virtual
void
finalize
(
const
std
::
vector
<
Mat
*>
&
inputs
,
std
::
vector
<
Mat
>
&
outputs
)
{
softmaxOp
.
release
();
}
bool
forward_ocl
(
InputArrayOfArrays
inps
,
OutputArrayOfArrays
outs
,
OutputArrayOfArrays
itns
)
{
std
::
vector
<
UMat
>
inputs
;
...
...
modules/dnn/test/test_backends.cpp
View file @
5b868ccd
...
...
@@ -10,9 +10,6 @@
namespace
opencv_test
{
namespace
{
CV_ENUM
(
DNNBackend
,
DNN_BACKEND_DEFAULT
,
DNN_BACKEND_HALIDE
,
DNN_BACKEND_INFERENCE_ENGINE
)
CV_ENUM
(
DNNTarget
,
DNN_TARGET_CPU
,
DNN_TARGET_OPENCL
)
static
void
loadNet
(
const
std
::
string
&
weights
,
const
std
::
string
&
proto
,
const
std
::
string
&
framework
,
Net
*
net
)
{
...
...
modules/dnn/test/test_caffe_importer.cpp
View file @
5b868ccd
...
...
@@ -42,8 +42,6 @@
#include "test_precomp.hpp"
#include "npy_blob.hpp"
#include <opencv2/dnn/shape_utils.hpp>
#include <opencv2/core/ocl.hpp>
#include <opencv2/ts/ocl_test.hpp>
namespace
opencv_test
{
namespace
{
...
...
@@ -83,10 +81,10 @@ TEST(Test_Caffe, read_googlenet)
ASSERT_FALSE
(
net
.
empty
());
}
typedef
testing
::
TestWithParam
<
bool
>
Reproducibility_AlexNet
;
typedef
testing
::
TestWithParam
<
tuple
<
bool
,
DNNTarget
>
>
Reproducibility_AlexNet
;
TEST_P
(
Reproducibility_AlexNet
,
Accuracy
)
{
bool
readFromMemory
=
GetParam
(
);
bool
readFromMemory
=
get
<
0
>
(
GetParam
()
);
Net
net
;
{
const
string
proto
=
findDataFile
(
"dnn/bvlc_alexnet.prototxt"
,
false
);
...
...
@@ -106,42 +104,7 @@ TEST_P(Reproducibility_AlexNet, Accuracy)
ASSERT_FALSE
(
net
.
empty
());
}
Mat
sample
=
imread
(
_tf
(
"grace_hopper_227.png"
));
ASSERT_TRUE
(
!
sample
.
empty
());
net
.
setInput
(
blobFromImage
(
sample
,
1.0
f
,
Size
(
227
,
227
),
Scalar
(),
false
),
"data"
);
Mat
out
=
net
.
forward
(
"prob"
);
Mat
ref
=
blobFromNPY
(
_tf
(
"caffe_alexnet_prob.npy"
));
normAssert
(
ref
,
out
);
}
INSTANTIATE_TEST_CASE_P
(
Test_Caffe
,
Reproducibility_AlexNet
,
testing
::
Bool
());
typedef
testing
::
TestWithParam
<
bool
>
Reproducibility_OCL_AlexNet
;
OCL_TEST_P
(
Reproducibility_OCL_AlexNet
,
Accuracy
)
{
bool
readFromMemory
=
GetParam
();
Net
net
;
{
const
string
proto
=
findDataFile
(
"dnn/bvlc_alexnet.prototxt"
,
false
);
const
string
model
=
findDataFile
(
"dnn/bvlc_alexnet.caffemodel"
,
false
);
if
(
readFromMemory
)
{
string
dataProto
;
ASSERT_TRUE
(
readFileInMemory
(
proto
,
dataProto
));
string
dataModel
;
ASSERT_TRUE
(
readFileInMemory
(
model
,
dataModel
));
net
=
readNetFromCaffe
(
dataProto
.
c_str
(),
dataProto
.
size
(),
dataModel
.
c_str
(),
dataModel
.
size
());
}
else
net
=
readNetFromCaffe
(
proto
,
model
);
ASSERT_FALSE
(
net
.
empty
());
}
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
net
.
setPreferableTarget
(
get
<
1
>
(
GetParam
()));
Mat
sample
=
imread
(
_tf
(
"grace_hopper_227.png"
));
ASSERT_TRUE
(
!
sample
.
empty
());
...
...
@@ -152,7 +115,7 @@ OCL_TEST_P(Reproducibility_OCL_AlexNet, Accuracy)
normAssert
(
ref
,
out
);
}
OCL_INSTANTIATE_TEST_CASE_P
(
Test_Caffe
,
Reproducibility_OCL_AlexNet
,
testing
::
Bool
(
));
INSTANTIATE_TEST_CASE_P
(
/**/
,
Reproducibility_AlexNet
,
Combine
(
testing
::
Bool
(),
availableDnnTargets
()
));
#if !defined(_WIN32) || defined(_WIN64)
TEST
(
Reproducibility_FCN
,
Accuracy
)
...
...
@@ -207,43 +170,14 @@ TEST(Reproducibility_SSD, Accuracy)
normAssert
(
ref
,
out
);
}
TEST
(
Reproducibility_MobileNet_SSD
,
Accuracy
)
{
const
string
proto
=
findDataFile
(
"dnn/MobileNetSSD_deploy.prototxt"
,
false
);
const
string
model
=
findDataFile
(
"dnn/MobileNetSSD_deploy.caffemodel"
,
false
);
Net
net
=
readNetFromCaffe
(
proto
,
model
);
Mat
sample
=
imread
(
_tf
(
"street.png"
));
Mat
inp
=
blobFromImage
(
sample
,
1.0
f
/
127.5
,
Size
(
300
,
300
),
Scalar
(
127.5
,
127.5
,
127.5
),
false
);
net
.
setInput
(
inp
);
Mat
out
=
net
.
forward
();
Mat
ref
=
blobFromNPY
(
_tf
(
"mobilenet_ssd_caffe_out.npy"
));
normAssert
(
ref
,
out
);
// Check that detections aren't preserved.
inp
.
setTo
(
0.0
f
);
net
.
setInput
(
inp
);
out
=
net
.
forward
();
const
int
numDetections
=
out
.
size
[
2
];
ASSERT_NE
(
numDetections
,
0
);
for
(
int
i
=
0
;
i
<
numDetections
;
++
i
)
{
float
confidence
=
out
.
ptr
<
float
>
(
0
,
0
,
i
)[
2
];
ASSERT_EQ
(
confidence
,
0
);
}
}
OCL_TEST
(
Reproducibility_MobileNet_SSD
,
Accuracy
)
typedef
testing
::
TestWithParam
<
DNNTarget
>
Reproducibility_MobileNet_SSD
;
TEST_P
(
Reproducibility_MobileNet_SSD
,
Accuracy
)
{
const
string
proto
=
findDataFile
(
"dnn/MobileNetSSD_deploy.prototxt"
,
false
);
const
string
model
=
findDataFile
(
"dnn/MobileNetSSD_deploy.caffemodel"
,
false
);
Net
net
=
readNetFromCaffe
(
proto
,
model
);
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
net
.
setPreferableTarget
(
GetParam
());
Mat
sample
=
imread
(
_tf
(
"street.png"
));
...
...
@@ -258,38 +192,39 @@ OCL_TEST(Reproducibility_MobileNet_SSD, Accuracy)
inp
.
setTo
(
0.0
f
);
net
.
setInput
(
inp
);
out
=
net
.
forward
();
out
=
out
.
reshape
(
1
,
out
.
total
()
/
7
);
const
int
numDetections
=
out
.
size
[
2
]
;
const
int
numDetections
=
out
.
rows
;
ASSERT_NE
(
numDetections
,
0
);
for
(
int
i
=
0
;
i
<
numDetections
;
++
i
)
{
float
confidence
=
out
.
ptr
<
float
>
(
0
,
0
,
i
)[
2
];
float
confidence
=
out
.
ptr
<
float
>
(
i
)[
2
];
ASSERT_EQ
(
confidence
,
0
);
}
}
TEST
(
Reproducibility_ResNet50
,
Accuracy
)
{
Net
net
=
readNetFromCaffe
(
findDataFile
(
"dnn/ResNet-50-deploy.prototxt"
,
false
),
findDataFile
(
"dnn/ResNet-50-model.caffemodel"
,
false
));
Mat
input
=
blobFromImage
(
imread
(
_tf
(
"googlenet_0.png"
)),
1.0
f
,
Size
(
224
,
224
),
Scalar
(),
false
);
ASSERT_TRUE
(
!
input
.
empty
());
net
.
setInput
(
input
);
Mat
out
=
net
.
forward
();
Mat
ref
=
blobFromNPY
(
_tf
(
"resnet50_prob.npy"
));
normAssert
(
ref
,
out
);
// Check batching mode.
ref
=
ref
.
reshape
(
1
,
numDetections
);
inp
=
blobFromImages
(
std
::
vector
<
Mat
>
(
2
,
sample
),
1.0
f
/
127.5
,
Size
(
300
,
300
),
Scalar
(
127.5
,
127.5
,
127.5
),
false
);
net
.
setInput
(
inp
);
Mat
outBatch
=
net
.
forward
();
// Output blob has a shape 1x1x2Nx7 where N is a number of detection for
// a single sample in batch. The first numbers of detection vectors are batch id.
outBatch
=
outBatch
.
reshape
(
1
,
outBatch
.
total
()
/
7
);
EXPECT_EQ
(
outBatch
.
rows
,
2
*
numDetections
);
normAssert
(
outBatch
.
rowRange
(
0
,
numDetections
),
ref
);
normAssert
(
outBatch
.
rowRange
(
numDetections
,
2
*
numDetections
).
colRange
(
1
,
7
),
ref
.
colRange
(
1
,
7
));
}
INSTANTIATE_TEST_CASE_P
(
/**/
,
Reproducibility_MobileNet_SSD
,
availableDnnTargets
());
OCL_TEST
(
Reproducibility_ResNet50
,
Accuracy
)
typedef
testing
::
TestWithParam
<
DNNTarget
>
Reproducibility_ResNet50
;
TEST_P
(
Reproducibility_ResNet50
,
Accuracy
)
{
Net
net
=
readNetFromCaffe
(
findDataFile
(
"dnn/ResNet-50-deploy.prototxt"
,
false
),
findDataFile
(
"dnn/ResNet-50-model.caffemodel"
,
false
));
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
int
targetId
=
GetParam
(
);
net
.
setPreferableTarget
(
targetId
);
Mat
input
=
blobFromImage
(
imread
(
_tf
(
"googlenet_0.png"
)),
1.0
f
,
Size
(
224
,
224
),
Scalar
(),
false
);
ASSERT_TRUE
(
!
input
.
empty
());
...
...
@@ -300,52 +235,46 @@ OCL_TEST(Reproducibility_ResNet50, Accuracy)
Mat
ref
=
blobFromNPY
(
_tf
(
"resnet50_prob.npy"
));
normAssert
(
ref
,
out
);
UMat
out_umat
;
net
.
forward
(
out_umat
);
normAssert
(
ref
,
out_umat
,
"out_umat"
);
std
::
vector
<
UMat
>
out_umats
;
net
.
forward
(
out_umats
);
normAssert
(
ref
,
out_umats
[
0
],
"out_umat_vector"
);
}
TEST
(
Reproducibility_SqueezeNet_v1_1
,
Accuracy
)
{
Net
net
=
readNetFromCaffe
(
findDataFile
(
"dnn/squeezenet_v1.1.prototxt"
,
false
),
findDataFile
(
"dnn/squeezenet_v1.1.caffemodel"
,
false
));
Mat
input
=
blobFromImage
(
imread
(
_tf
(
"googlenet_0.png"
)),
1.0
f
,
Size
(
227
,
227
),
Scalar
(),
false
);
ASSERT_TRUE
(
!
input
.
empty
());
net
.
setInput
(
input
);
Mat
out
=
net
.
forward
();
if
(
targetId
==
DNN_TARGET_OPENCL
)
{
UMat
out_umat
;
net
.
forward
(
out_umat
);
normAssert
(
ref
,
out_umat
,
"out_umat"
);
Mat
ref
=
blobFromNPY
(
_tf
(
"squeezenet_v1.1_prob.npy"
));
normAssert
(
ref
,
out
);
std
::
vector
<
UMat
>
out_umats
;
net
.
forward
(
out_umats
);
normAssert
(
ref
,
out_umats
[
0
],
"out_umat_vector"
);
}
}
INSTANTIATE_TEST_CASE_P
(
/**/
,
Reproducibility_ResNet50
,
availableDnnTargets
());
OCL_TEST
(
Reproducibility_SqueezeNet_v1_1
,
Accuracy
)
typedef
testing
::
TestWithParam
<
DNNTarget
>
Reproducibility_SqueezeNet_v1_1
;
TEST_P
(
Reproducibility_SqueezeNet_v1_1
,
Accuracy
)
{
Net
net
=
readNetFromCaffe
(
findDataFile
(
"dnn/squeezenet_v1.1.prototxt"
,
false
),
findDataFile
(
"dnn/squeezenet_v1.1.caffemodel"
,
false
));
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
int
targetId
=
GetParam
(
);
net
.
setPreferableTarget
(
targetId
);
Mat
input
=
blobFromImage
(
imread
(
_tf
(
"googlenet_0.png"
)),
1.0
f
,
Size
(
227
,
227
),
Scalar
(),
false
);
ASSERT_TRUE
(
!
input
.
empty
());
// Firstly set a wrong input blob and run the model to receive a wrong output.
net
.
setInput
(
input
*
2.0
f
);
Mat
out
=
net
.
forward
();
// Then set a correct input blob to check CPU->GPU synchronization is working well.
Mat
out
;
if
(
targetId
==
DNN_TARGET_OPENCL
)
{
// Firstly set a wrong input blob and run the model to receive a wrong output.
// Then set a correct input blob to check CPU->GPU synchronization is working well.
net
.
setInput
(
input
*
2.0
f
);
out
=
net
.
forward
();
}
net
.
setInput
(
input
);
out
=
net
.
forward
();
Mat
ref
=
blobFromNPY
(
_tf
(
"squeezenet_v1.1_prob.npy"
));
normAssert
(
ref
,
out
);
}
INSTANTIATE_TEST_CASE_P
(
/**/
,
Reproducibility_SqueezeNet_v1_1
,
availableDnnTargets
());
TEST
(
Reproducibility_AlexNet_fp16
,
Accuracy
)
{
...
...
@@ -456,7 +385,6 @@ TEST(Test_Caffe, multiple_inputs)
normAssert
(
out
,
first_image
+
second_image
);
}
CV_ENUM
(
DNNTarget
,
DNN_TARGET_CPU
,
DNN_TARGET_OPENCL
)
typedef
testing
::
TestWithParam
<
tuple
<
std
::
string
,
DNNTarget
>
>
opencv_face_detector
;
TEST_P
(
opencv_face_detector
,
Accuracy
)
{
...
...
modules/dnn/test/test_googlenet.cpp
View file @
5b868ccd
...
...
@@ -77,6 +77,10 @@ OCL_TEST(Reproducibility_GoogLeNet, Accuracy)
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
// Initialize network for a single image in the batch but test with batch size=2.
net
.
setInput
(
blobFromImage
(
Mat
(
224
,
224
,
CV_8UC3
)));
net
.
forward
();
std
::
vector
<
Mat
>
inpMats
;
inpMats
.
push_back
(
imread
(
_tf
(
"googlenet_0.png"
))
);
inpMats
.
push_back
(
imread
(
_tf
(
"googlenet_1.png"
))
);
...
...
modules/dnn/test/test_precomp.hpp
View file @
5b868ccd
...
...
@@ -44,12 +44,31 @@
#include "opencv2/ts.hpp"
#include "opencv2/ts/ts_perf.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/core/ocl.hpp"
#include "opencv2/dnn.hpp"
#include "test_common.hpp"
namespace
opencv_test
{
using
namespace
cv
::
dnn
;
CV_ENUM
(
DNNBackend
,
DNN_BACKEND_DEFAULT
,
DNN_BACKEND_HALIDE
,
DNN_BACKEND_INFERENCE_ENGINE
)
CV_ENUM
(
DNNTarget
,
DNN_TARGET_CPU
,
DNN_TARGET_OPENCL
)
static
testing
::
internal
::
ParamGenerator
<
DNNTarget
>
availableDnnTargets
()
{
static
std
::
vector
<
DNNTarget
>
targets
;
if
(
targets
.
empty
())
{
targets
.
push_back
(
DNN_TARGET_CPU
);
#ifdef HAVE_OPENCL
if
(
cv
::
ocl
::
useOpenCL
())
targets
.
push_back
(
DNN_TARGET_OPENCL
);
#endif
}
return
testing
::
ValuesIn
(
targets
);
}
}
#endif
modules/dnn/test/test_tf_importer.cpp
View file @
5b868ccd
This diff is collapsed.
Click to expand it.
modules/dnn/test/test_torch_importer.cpp
View file @
5b868ccd
This diff is collapsed.
Click to expand it.
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