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
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
250 additions
and
468 deletions
+250
-468
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
+42
-114
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
+96
-167
test_torch_importer.cpp
modules/dnn/test/test_torch_importer.cpp
+67
-184
No files found.
modules/dnn/src/layers/convolution_layer.cpp
View file @
5b868ccd
...
@@ -273,6 +273,9 @@ public:
...
@@ -273,6 +273,9 @@ public:
for
(
int
i
=
0
;
i
<
outCn
;
i
++
)
for
(
int
i
=
0
;
i
<
outCn
;
i
++
)
biasvec
[
i
]
=
biasMat
.
at
<
float
>
(
i
);
biasvec
[
i
]
=
biasMat
.
at
<
float
>
(
i
);
}
}
#ifdef HAVE_OPENCL
convolutionOp
.
release
();
#endif
}
}
bool
setActivation
(
const
Ptr
<
ActivationLayer
>&
layer
)
bool
setActivation
(
const
Ptr
<
ActivationLayer
>&
layer
)
...
...
modules/dnn/src/layers/fully_connected_layer.cpp
View file @
5b868ccd
...
@@ -267,6 +267,11 @@ public:
...
@@ -267,6 +267,11 @@ public:
};
};
#ifdef HAVE_OPENCL
#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
)
bool
forward_ocl
(
InputArrayOfArrays
inps
,
OutputArrayOfArrays
outs
,
InputArrayOfArrays
internals
)
{
{
std
::
vector
<
UMat
>
inputs
;
std
::
vector
<
UMat
>
inputs
;
...
...
modules/dnn/src/layers/lrn_layer.cpp
View file @
5b868ccd
...
@@ -96,6 +96,11 @@ public:
...
@@ -96,6 +96,11 @@ public:
}
}
#ifdef HAVE_OPENCL
#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
)
bool
forward_ocl
(
InputArrayOfArrays
inps
,
OutputArrayOfArrays
outs
,
OutputArrayOfArrays
internals
)
{
{
std
::
vector
<
UMat
>
inputs
;
std
::
vector
<
UMat
>
inputs
;
...
...
modules/dnn/src/layers/pooling_layer.cpp
View file @
5b868ccd
...
@@ -127,6 +127,10 @@ public:
...
@@ -127,6 +127,10 @@ public:
}
}
getConvPoolPaddings
(
inp
,
out
,
kernel
,
stride
,
padMode
,
Size
(
1
,
1
),
pad
);
getConvPoolPaddings
(
inp
,
out
,
kernel
,
stride
,
padMode
,
Size
(
1
,
1
),
pad
);
#ifdef HAVE_OPENCL
poolOp
.
release
();
#endif
}
}
virtual
bool
supportBackend
(
int
backendId
)
virtual
bool
supportBackend
(
int
backendId
)
...
...
modules/dnn/src/layers/softmax_layer.cpp
View file @
5b868ccd
...
@@ -94,6 +94,11 @@ public:
...
@@ -94,6 +94,11 @@ public:
}
}
#ifdef HAVE_OPENCL
#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
)
bool
forward_ocl
(
InputArrayOfArrays
inps
,
OutputArrayOfArrays
outs
,
OutputArrayOfArrays
itns
)
{
{
std
::
vector
<
UMat
>
inputs
;
std
::
vector
<
UMat
>
inputs
;
...
...
modules/dnn/test/test_backends.cpp
View file @
5b868ccd
...
@@ -10,9 +10,6 @@
...
@@ -10,9 +10,6 @@
namespace
opencv_test
{
namespace
{
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
,
static
void
loadNet
(
const
std
::
string
&
weights
,
const
std
::
string
&
proto
,
const
std
::
string
&
framework
,
Net
*
net
)
const
std
::
string
&
framework
,
Net
*
net
)
{
{
...
...
modules/dnn/test/test_caffe_importer.cpp
View file @
5b868ccd
...
@@ -42,8 +42,6 @@
...
@@ -42,8 +42,6 @@
#include "test_precomp.hpp"
#include "test_precomp.hpp"
#include "npy_blob.hpp"
#include "npy_blob.hpp"
#include <opencv2/dnn/shape_utils.hpp>
#include <opencv2/dnn/shape_utils.hpp>
#include <opencv2/core/ocl.hpp>
#include <opencv2/ts/ocl_test.hpp>
namespace
opencv_test
{
namespace
{
namespace
opencv_test
{
namespace
{
...
@@ -83,10 +81,10 @@ TEST(Test_Caffe, read_googlenet)
...
@@ -83,10 +81,10 @@ TEST(Test_Caffe, read_googlenet)
ASSERT_FALSE
(
net
.
empty
());
ASSERT_FALSE
(
net
.
empty
());
}
}
typedef
testing
::
TestWithParam
<
bool
>
Reproducibility_AlexNet
;
typedef
testing
::
TestWithParam
<
tuple
<
bool
,
DNNTarget
>
>
Reproducibility_AlexNet
;
TEST_P
(
Reproducibility_AlexNet
,
Accuracy
)
TEST_P
(
Reproducibility_AlexNet
,
Accuracy
)
{
{
bool
readFromMemory
=
GetParam
(
);
bool
readFromMemory
=
get
<
0
>
(
GetParam
()
);
Net
net
;
Net
net
;
{
{
const
string
proto
=
findDataFile
(
"dnn/bvlc_alexnet.prototxt"
,
false
);
const
string
proto
=
findDataFile
(
"dnn/bvlc_alexnet.prototxt"
,
false
);
...
@@ -106,42 +104,7 @@ TEST_P(Reproducibility_AlexNet, Accuracy)
...
@@ -106,42 +104,7 @@ TEST_P(Reproducibility_AlexNet, Accuracy)
ASSERT_FALSE
(
net
.
empty
());
ASSERT_FALSE
(
net
.
empty
());
}
}
Mat
sample
=
imread
(
_tf
(
"grace_hopper_227.png"
));
net
.
setPreferableTarget
(
get
<
1
>
(
GetParam
()));
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
);
Mat
sample
=
imread
(
_tf
(
"grace_hopper_227.png"
));
Mat
sample
=
imread
(
_tf
(
"grace_hopper_227.png"
));
ASSERT_TRUE
(
!
sample
.
empty
());
ASSERT_TRUE
(
!
sample
.
empty
());
...
@@ -152,7 +115,7 @@ OCL_TEST_P(Reproducibility_OCL_AlexNet, Accuracy)
...
@@ -152,7 +115,7 @@ OCL_TEST_P(Reproducibility_OCL_AlexNet, Accuracy)
normAssert
(
ref
,
out
);
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)
#if !defined(_WIN32) || defined(_WIN64)
TEST
(
Reproducibility_FCN
,
Accuracy
)
TEST
(
Reproducibility_FCN
,
Accuracy
)
...
@@ -207,43 +170,14 @@ TEST(Reproducibility_SSD, Accuracy)
...
@@ -207,43 +170,14 @@ TEST(Reproducibility_SSD, Accuracy)
normAssert
(
ref
,
out
);
normAssert
(
ref
,
out
);
}
}
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
);
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
)
{
{
const
string
proto
=
findDataFile
(
"dnn/MobileNetSSD_deploy.prototxt"
,
false
);
const
string
proto
=
findDataFile
(
"dnn/MobileNetSSD_deploy.prototxt"
,
false
);
const
string
model
=
findDataFile
(
"dnn/MobileNetSSD_deploy.caffemodel"
,
false
);
const
string
model
=
findDataFile
(
"dnn/MobileNetSSD_deploy.caffemodel"
,
false
);
Net
net
=
readNetFromCaffe
(
proto
,
model
);
Net
net
=
readNetFromCaffe
(
proto
,
model
);
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
GetParam
());
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
Mat
sample
=
imread
(
_tf
(
"street.png"
));
Mat
sample
=
imread
(
_tf
(
"street.png"
));
...
@@ -258,38 +192,39 @@ OCL_TEST(Reproducibility_MobileNet_SSD, Accuracy)
...
@@ -258,38 +192,39 @@ OCL_TEST(Reproducibility_MobileNet_SSD, Accuracy)
inp
.
setTo
(
0.0
f
);
inp
.
setTo
(
0.0
f
);
net
.
setInput
(
inp
);
net
.
setInput
(
inp
);
out
=
net
.
forward
();
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
);
ASSERT_NE
(
numDetections
,
0
);
for
(
int
i
=
0
;
i
<
numDetections
;
++
i
)
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
);
ASSERT_EQ
(
confidence
,
0
);
}
}
}
TEST
(
Reproducibility_ResNet50
,
Accuracy
)
// Check batching mode.
{
ref
=
ref
.
reshape
(
1
,
numDetections
);
Net
net
=
readNetFromCaffe
(
findDataFile
(
"dnn/ResNet-50-deploy.prototxt"
,
false
),
inp
=
blobFromImages
(
std
::
vector
<
Mat
>
(
2
,
sample
),
1.0
f
/
127.5
,
Size
(
300
,
300
),
Scalar
(
127.5
,
127.5
,
127.5
),
false
);
findDataFile
(
"dnn/ResNet-50-model.caffemodel"
,
false
));
net
.
setInput
(
inp
);
Mat
outBatch
=
net
.
forward
();
Mat
input
=
blobFromImage
(
imread
(
_tf
(
"googlenet_0.png"
)),
1.0
f
,
Size
(
224
,
224
),
Scalar
(),
false
);
ASSERT_TRUE
(
!
input
.
empty
());
// 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.
net
.
setInput
(
input
);
outBatch
=
outBatch
.
reshape
(
1
,
outBatch
.
total
()
/
7
);
Mat
out
=
net
.
forward
();
EXPECT_EQ
(
outBatch
.
rows
,
2
*
numDetections
);
normAssert
(
outBatch
.
rowRange
(
0
,
numDetections
),
ref
);
Mat
ref
=
blobFromNPY
(
_tf
(
"resnet50_prob.npy"
));
normAssert
(
outBatch
.
rowRange
(
numDetections
,
2
*
numDetections
).
colRange
(
1
,
7
),
ref
.
colRange
(
1
,
7
));
normAssert
(
ref
,
out
);
}
}
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
),
Net
net
=
readNetFromCaffe
(
findDataFile
(
"dnn/ResNet-50-deploy.prototxt"
,
false
),
findDataFile
(
"dnn/ResNet-50-model.caffemodel"
,
false
));
findDataFile
(
"dnn/ResNet-50-model.caffemodel"
,
false
));
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
int
targetId
=
GetParam
(
);
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
net
.
setPreferableTarget
(
targetId
);
Mat
input
=
blobFromImage
(
imread
(
_tf
(
"googlenet_0.png"
)),
1.0
f
,
Size
(
224
,
224
),
Scalar
(),
false
);
Mat
input
=
blobFromImage
(
imread
(
_tf
(
"googlenet_0.png"
)),
1.0
f
,
Size
(
224
,
224
),
Scalar
(),
false
);
ASSERT_TRUE
(
!
input
.
empty
());
ASSERT_TRUE
(
!
input
.
empty
());
...
@@ -300,6 +235,8 @@ OCL_TEST(Reproducibility_ResNet50, Accuracy)
...
@@ -300,6 +235,8 @@ OCL_TEST(Reproducibility_ResNet50, Accuracy)
Mat
ref
=
blobFromNPY
(
_tf
(
"resnet50_prob.npy"
));
Mat
ref
=
blobFromNPY
(
_tf
(
"resnet50_prob.npy"
));
normAssert
(
ref
,
out
);
normAssert
(
ref
,
out
);
if
(
targetId
==
DNN_TARGET_OPENCL
)
{
UMat
out_umat
;
UMat
out_umat
;
net
.
forward
(
out_umat
);
net
.
forward
(
out_umat
);
normAssert
(
ref
,
out_umat
,
"out_umat"
);
normAssert
(
ref
,
out_umat
,
"out_umat"
);
...
@@ -307,45 +244,37 @@ OCL_TEST(Reproducibility_ResNet50, Accuracy)
...
@@ -307,45 +244,37 @@ OCL_TEST(Reproducibility_ResNet50, Accuracy)
std
::
vector
<
UMat
>
out_umats
;
std
::
vector
<
UMat
>
out_umats
;
net
.
forward
(
out_umats
);
net
.
forward
(
out_umats
);
normAssert
(
ref
,
out_umats
[
0
],
"out_umat_vector"
);
normAssert
(
ref
,
out_umats
[
0
],
"out_umat_vector"
);
}
}
}
INSTANTIATE_TEST_CASE_P
(
/**/
,
Reproducibility_ResNet50
,
availableDnnTargets
());
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
));
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
();
Mat
ref
=
blobFromNPY
(
_tf
(
"squeezenet_v1.1_prob.npy"
));
normAssert
(
ref
,
out
);
}
OCL_TEST
(
Reproducibility_SqueezeNet_v1_1
,
Accuracy
)
{
{
Net
net
=
readNetFromCaffe
(
findDataFile
(
"dnn/squeezenet_v1.1.prototxt"
,
false
),
Net
net
=
readNetFromCaffe
(
findDataFile
(
"dnn/squeezenet_v1.1.prototxt"
,
false
),
findDataFile
(
"dnn/squeezenet_v1.1.caffemodel"
,
false
));
findDataFile
(
"dnn/squeezenet_v1.1.caffemodel"
,
false
));
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
int
targetId
=
GetParam
(
);
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
net
.
setPreferableTarget
(
targetId
);
Mat
input
=
blobFromImage
(
imread
(
_tf
(
"googlenet_0.png"
)),
1.0
f
,
Size
(
227
,
227
),
Scalar
(),
false
);
Mat
input
=
blobFromImage
(
imread
(
_tf
(
"googlenet_0.png"
)),
1.0
f
,
Size
(
227
,
227
),
Scalar
(),
false
);
ASSERT_TRUE
(
!
input
.
empty
());
ASSERT_TRUE
(
!
input
.
empty
());
Mat
out
;
if
(
targetId
==
DNN_TARGET_OPENCL
)
{
// Firstly set a wrong input blob and run the model to receive a wrong output.
// 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.
// 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
);
net
.
setInput
(
input
);
out
=
net
.
forward
();
out
=
net
.
forward
();
Mat
ref
=
blobFromNPY
(
_tf
(
"squeezenet_v1.1_prob.npy"
));
Mat
ref
=
blobFromNPY
(
_tf
(
"squeezenet_v1.1_prob.npy"
));
normAssert
(
ref
,
out
);
normAssert
(
ref
,
out
);
}
}
INSTANTIATE_TEST_CASE_P
(
/**/
,
Reproducibility_SqueezeNet_v1_1
,
availableDnnTargets
());
TEST
(
Reproducibility_AlexNet_fp16
,
Accuracy
)
TEST
(
Reproducibility_AlexNet_fp16
,
Accuracy
)
{
{
...
@@ -456,7 +385,6 @@ TEST(Test_Caffe, multiple_inputs)
...
@@ -456,7 +385,6 @@ TEST(Test_Caffe, multiple_inputs)
normAssert
(
out
,
first_image
+
second_image
);
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
;
typedef
testing
::
TestWithParam
<
tuple
<
std
::
string
,
DNNTarget
>
>
opencv_face_detector
;
TEST_P
(
opencv_face_detector
,
Accuracy
)
TEST_P
(
opencv_face_detector
,
Accuracy
)
{
{
...
...
modules/dnn/test/test_googlenet.cpp
View file @
5b868ccd
...
@@ -77,6 +77,10 @@ OCL_TEST(Reproducibility_GoogLeNet, Accuracy)
...
@@ -77,6 +77,10 @@ OCL_TEST(Reproducibility_GoogLeNet, Accuracy)
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
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
;
std
::
vector
<
Mat
>
inpMats
;
inpMats
.
push_back
(
imread
(
_tf
(
"googlenet_0.png"
))
);
inpMats
.
push_back
(
imread
(
_tf
(
"googlenet_0.png"
))
);
inpMats
.
push_back
(
imread
(
_tf
(
"googlenet_1.png"
))
);
inpMats
.
push_back
(
imread
(
_tf
(
"googlenet_1.png"
))
);
...
...
modules/dnn/test/test_precomp.hpp
View file @
5b868ccd
...
@@ -44,12 +44,31 @@
...
@@ -44,12 +44,31 @@
#include "opencv2/ts.hpp"
#include "opencv2/ts.hpp"
#include "opencv2/ts/ts_perf.hpp"
#include "opencv2/ts/ts_perf.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/core/ocl.hpp"
#include "opencv2/dnn.hpp"
#include "opencv2/dnn.hpp"
#include "test_common.hpp"
#include "test_common.hpp"
namespace
opencv_test
{
namespace
opencv_test
{
using
namespace
cv
::
dnn
;
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
#endif
modules/dnn/test/test_tf_importer.cpp
View file @
5b868ccd
...
@@ -11,8 +11,6 @@ Test for Tensorflow models loading
...
@@ -11,8 +11,6 @@ Test for Tensorflow models loading
#include "test_precomp.hpp"
#include "test_precomp.hpp"
#include "npy_blob.hpp"
#include "npy_blob.hpp"
#include <opencv2/core/ocl.hpp>
#include <opencv2/ts/ocl_test.hpp>
namespace
opencv_test
namespace
opencv_test
{
{
...
@@ -115,118 +113,85 @@ static void runTensorFlowNet(const std::string& prefix, int targetId = DNN_TARGE
...
@@ -115,118 +113,85 @@ static void runTensorFlowNet(const std::string& prefix, int targetId = DNN_TARGE
normAssert
(
target
,
output
,
""
,
l1
,
lInf
);
normAssert
(
target
,
output
,
""
,
l1
,
lInf
);
}
}
TEST
(
Test_TensorFlow
,
conv
)
typedef
testing
::
TestWithParam
<
DNNTarget
>
Test_TensorFlow_layers
;
{
runTensorFlowNet
(
"single_conv"
);
runTensorFlowNet
(
"atrous_conv2d_valid"
);
runTensorFlowNet
(
"atrous_conv2d_same"
);
runTensorFlowNet
(
"depthwise_conv2d"
);
}
TEST
(
Test_TensorFlow
,
padding
)
TEST
_P
(
Test_TensorFlow_layers
,
conv
)
{
{
runTensorFlowNet
(
"padding_same"
);
int
targetId
=
GetParam
();
runTensorFlowNet
(
"padding_valid"
);
runTensorFlowNet
(
"single_conv"
,
targetId
);
runTensorFlowNet
(
"spatial_padding"
);
runTensorFlowNet
(
"atrous_conv2d_valid"
,
targetId
);
runTensorFlowNet
(
"atrous_conv2d_same"
,
targetId
);
runTensorFlowNet
(
"depthwise_conv2d"
,
targetId
);
}
}
TEST
(
Test_TensorFlow
,
eltwise_add_mul
)
TEST
_P
(
Test_TensorFlow_layers
,
padding
)
{
{
runTensorFlowNet
(
"eltwise_add_mul"
);
int
targetId
=
GetParam
();
runTensorFlowNet
(
"padding_same"
,
targetId
);
runTensorFlowNet
(
"padding_valid"
,
targetId
);
runTensorFlowNet
(
"spatial_padding"
,
targetId
);
}
}
OCL_TEST
(
Test_TensorFlow
,
eltwise_add_mul
)
TEST_P
(
Test_TensorFlow_layers
,
eltwise_add_mul
)
{
{
runTensorFlowNet
(
"eltwise_add_mul"
,
DNN_TARGET_OPENCL
);
runTensorFlowNet
(
"eltwise_add_mul"
,
GetParam
()
);
}
}
TEST
(
Test_TensorFlow
,
pad_and_concat
)
TEST
_P
(
Test_TensorFlow_layers
,
pad_and_concat
)
{
{
runTensorFlowNet
(
"pad_and_concat"
);
runTensorFlowNet
(
"pad_and_concat"
,
GetParam
()
);
}
}
TEST
(
Test_TensorFlow
,
batch_norm
)
TEST
_P
(
Test_TensorFlow_layers
,
batch_norm
)
{
{
runTensorFlowNet
(
"batch_norm"
);
int
targetId
=
GetParam
();
runTensorFlowNet
(
"fused_batch_norm"
);
runTensorFlowNet
(
"batch_norm"
,
targetId
);
runTensorFlowNet
(
"batch_norm_text"
,
DNN_TARGET_CPU
,
true
);
runTensorFlowNet
(
"fused_batch_norm"
,
targetId
);
runTensorFlowNet
(
"mvn_batch_norm"
);
runTensorFlowNet
(
"batch_norm_text"
,
targetId
,
true
);
runTensorFlowNet
(
"mvn_batch_norm_1x1"
);
runTensorFlowNet
(
"mvn_batch_norm"
,
targetId
);
runTensorFlowNet
(
"mvn_batch_norm_1x1"
,
targetId
);
}
}
OCL_TEST
(
Test_TensorFlow
,
batch_norm
)
TEST_P
(
Test_TensorFlow_layers
,
pooling
)
{
{
runTensorFlowNet
(
"batch_norm"
,
DNN_TARGET_OPENCL
);
int
targetId
=
GetParam
();
runTensorFlowNet
(
"fused_batch_norm"
,
DNN_TARGET_OPENCL
);
runTensorFlowNet
(
"max_pool_even"
,
targetId
);
runTensorFlowNet
(
"batch_norm_text"
,
DNN_TARGET_OPENCL
,
true
);
runTensorFlowNet
(
"max_pool_odd_valid"
,
targetId
);
runTensorFlowNet
(
"ave_pool_same"
,
targetId
);
runTensorFlowNet
(
"max_pool_odd_same"
,
targetId
);
}
}
TEST
(
Test_TensorFlow
,
pooling
)
TEST
_P
(
Test_TensorFlow_layers
,
deconvolution
)
{
{
runTensorFlowNet
(
"max_pool_even"
);
int
targetId
=
GetParam
();
runTensorFlowNet
(
"max_pool_odd_valid"
);
runTensorFlowNet
(
"deconvolution"
,
targetId
);
runTensorFlowNet
(
"max_pool_odd_same"
);
runTensorFlowNet
(
"deconvolution_same"
,
targetId
);
runTensorFlowNet
(
"ave_pool_same"
);
runTensorFlowNet
(
"deconvolution_stride_2_same"
,
targetId
);
runTensorFlowNet
(
"deconvolution_adj_pad_valid"
,
targetId
);
runTensorFlowNet
(
"deconvolution_adj_pad_same"
,
targetId
);
}
}
TEST
(
Test_TensorFlow
,
deconvolution
)
TEST
_P
(
Test_TensorFlow_layers
,
matmul
)
{
{
runTensorFlowNet
(
"deconvolution"
);
int
targetId
=
GetParam
();
runTensorFlowNet
(
"deconvolution_same"
);
runTensorFlowNet
(
"matmul"
,
targetId
);
runTensorFlowNet
(
"deconvolution_stride_2_same"
);
runTensorFlowNet
(
"nhwc_reshape_matmul"
,
targetId
);
runTensorFlowNet
(
"deconvolution_adj_pad_valid"
);
runTensorFlowNet
(
"nhwc_transpose_reshape_matmul"
,
targetId
);
runTensorFlowNet
(
"deconvolution_adj_pad_same"
);
}
}
OCL_TEST
(
Test_TensorFlow
,
deconvolution
)
TEST_P
(
Test_TensorFlow_layers
,
reshape
)
{
{
runTensorFlowNet
(
"deconvolution"
,
DNN_TARGET_OPENCL
);
int
targetId
=
GetParam
();
runTensorFlowNet
(
"deconvolution_same"
,
DNN_TARGET_OPENCL
);
runTensorFlowNet
(
"shift_reshape_no_reorder"
,
targetId
);
runTensorFlowNet
(
"deconvolution_stride_2_same"
,
DNN_TARGET_OPENCL
);
runTensorFlowNet
(
"reshape_reduce"
,
targetId
);
runTensorFlowNet
(
"deconvolution_adj_pad_valid"
,
DNN_TARGET_OPENCL
);
runTensorFlowNet
(
"flatten"
,
targetId
,
true
);
runTensorFlowNet
(
"deconvolution_adj_pad_same"
,
DNN_TARGET_OPENCL
);
}
}
TEST
(
Test_TensorFlow
,
matmul
)
INSTANTIATE_TEST_CASE_P
(
/**/
,
Test_TensorFlow_layers
,
availableDnnTargets
());
{
runTensorFlowNet
(
"matmul"
);
runTensorFlowNet
(
"nhwc_reshape_matmul"
);
runTensorFlowNet
(
"nhwc_transpose_reshape_matmul"
);
}
TEST
(
Test_TensorFlow
,
defun
)
typedef
testing
::
TestWithParam
<
DNNTarget
>
Test_TensorFlow_nets
;
{
runTensorFlowNet
(
"defun_dropout"
);
}
TEST
(
Test_TensorFlow
,
reshape
)
TEST_P
(
Test_TensorFlow_nets
,
MobileNet_SSD
)
{
runTensorFlowNet
(
"shift_reshape_no_reorder"
);
runTensorFlowNet
(
"reshape_reduce"
);
runTensorFlowNet
(
"flatten"
,
DNN_TARGET_CPU
,
true
);
}
TEST
(
Test_TensorFlow
,
fp16
)
{
const
float
l1
=
1e-3
;
const
float
lInf
=
1e-2
;
runTensorFlowNet
(
"fp16_single_conv"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_deconvolution"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_max_pool_odd_same"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_padding_valid"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_eltwise_add_mul"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_max_pool_odd_valid"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_pad_and_concat"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_max_pool_even"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_padding_same"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
}
TEST
(
Test_TensorFlow
,
quantized
)
{
runTensorFlowNet
(
"uint8_single_conv"
);
}
TEST
(
Test_TensorFlow
,
MobileNet_SSD
)
{
{
std
::
string
netPath
=
findDataFile
(
"dnn/ssd_mobilenet_v1_coco.pb"
,
false
);
std
::
string
netPath
=
findDataFile
(
"dnn/ssd_mobilenet_v1_coco.pb"
,
false
);
std
::
string
netConfig
=
findDataFile
(
"dnn/ssd_mobilenet_v1_coco.pbtxt"
,
false
);
std
::
string
netConfig
=
findDataFile
(
"dnn/ssd_mobilenet_v1_coco.pbtxt"
,
false
);
...
@@ -249,17 +214,20 @@ TEST(Test_TensorFlow, MobileNet_SSD)
...
@@ -249,17 +214,20 @@ TEST(Test_TensorFlow, MobileNet_SSD)
}
}
Net
net
=
readNetFromTensorflow
(
netPath
,
netConfig
);
Net
net
=
readNetFromTensorflow
(
netPath
,
netConfig
);
net
.
setPreferableTarget
(
GetParam
());
net
.
setInput
(
inp
);
net
.
setInput
(
inp
);
std
::
vector
<
Mat
>
output
;
std
::
vector
<
Mat
>
output
;
net
.
forward
(
output
,
outNames
);
net
.
forward
(
output
,
outNames
);
normAssert
(
target
[
0
].
reshape
(
1
,
1
),
output
[
0
].
reshape
(
1
,
1
));
normAssert
(
target
[
0
].
reshape
(
1
,
1
),
output
[
0
].
reshape
(
1
,
1
)
,
""
,
1e-5
,
1.5e-4
);
normAssert
(
target
[
1
].
reshape
(
1
,
1
),
output
[
1
].
reshape
(
1
,
1
),
""
,
1e-5
,
3e-4
);
normAssert
(
target
[
1
].
reshape
(
1
,
1
),
output
[
1
].
reshape
(
1
,
1
),
""
,
1e-5
,
3e-4
);
normAssert
(
target
[
2
].
reshape
(
1
,
1
),
output
[
2
].
reshape
(
1
,
1
),
""
,
4e-5
,
1e-2
);
normAssert
(
target
[
2
].
reshape
(
1
,
1
),
output
[
2
].
reshape
(
1
,
1
),
""
,
4e-5
,
1e-2
);
}
}
TEST
(
Test_TensorFlow
,
Inception_v2_SSD
)
TEST
_P
(
Test_TensorFlow_nets
,
Inception_v2_SSD
)
{
{
std
::
string
proto
=
findDataFile
(
"dnn/ssd_inception_v2_coco_2017_11_17.pbtxt"
,
false
);
std
::
string
proto
=
findDataFile
(
"dnn/ssd_inception_v2_coco_2017_11_17.pbtxt"
,
false
);
std
::
string
model
=
findDataFile
(
"dnn/ssd_inception_v2_coco_2017_11_17.pb"
,
false
);
std
::
string
model
=
findDataFile
(
"dnn/ssd_inception_v2_coco_2017_11_17.pb"
,
false
);
...
@@ -268,6 +236,8 @@ TEST(Test_TensorFlow, Inception_v2_SSD)
...
@@ -268,6 +236,8 @@ TEST(Test_TensorFlow, Inception_v2_SSD)
Mat
img
=
imread
(
findDataFile
(
"dnn/street.png"
,
false
));
Mat
img
=
imread
(
findDataFile
(
"dnn/street.png"
,
false
));
Mat
blob
=
blobFromImage
(
img
,
1.0
f
/
127.5
,
Size
(
300
,
300
),
Scalar
(
127.5
,
127.5
,
127.5
),
true
,
false
);
Mat
blob
=
blobFromImage
(
img
,
1.0
f
/
127.5
,
Size
(
300
,
300
),
Scalar
(
127.5
,
127.5
,
127.5
),
true
,
false
);
net
.
setPreferableTarget
(
GetParam
());
net
.
setInput
(
blob
);
net
.
setInput
(
blob
);
// Output has shape 1x1xNx7 where N - number of detections.
// Output has shape 1x1xNx7 where N - number of detections.
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
...
@@ -289,74 +259,57 @@ TEST(Test_TensorFlow, Inception_v2_SSD)
...
@@ -289,74 +259,57 @@ TEST(Test_TensorFlow, Inception_v2_SSD)
normAssert
(
detections
,
ref
);
normAssert
(
detections
,
ref
);
}
}
OCL_TEST
(
Test_TensorFlow
,
MobileNet_SSD
)
TEST_P
(
Test_TensorFlow_nets
,
opencv_face_detector_uint8
)
{
std
::
string
netPath
=
findDataFile
(
"dnn/ssd_mobilenet_v1_coco.pb"
,
false
);
std
::
string
netConfig
=
findDataFile
(
"dnn/ssd_mobilenet_v1_coco.pbtxt"
,
false
);
std
::
string
imgPath
=
findDataFile
(
"dnn/street.png"
,
false
);
Mat
inp
;
resize
(
imread
(
imgPath
),
inp
,
Size
(
300
,
300
));
inp
=
blobFromImage
(
inp
,
1.0
f
/
127.5
,
Size
(),
Scalar
(
127.5
,
127.5
,
127.5
),
true
);
std
::
vector
<
String
>
outNames
(
3
);
outNames
[
0
]
=
"concat"
;
outNames
[
1
]
=
"concat_1"
;
outNames
[
2
]
=
"detection_out"
;
std
::
vector
<
Mat
>
target
(
outNames
.
size
());
for
(
int
i
=
0
;
i
<
outNames
.
size
();
++
i
)
{
std
::
string
path
=
findDataFile
(
"dnn/tensorflow/ssd_mobilenet_v1_coco."
+
outNames
[
i
]
+
".npy"
,
false
);
target
[
i
]
=
blobFromNPY
(
path
);
}
Net
net
=
readNetFromTensorflow
(
netPath
,
netConfig
);
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
net
.
setInput
(
inp
);
std
::
vector
<
Mat
>
output
;
net
.
forward
(
output
,
outNames
);
normAssert
(
target
[
0
].
reshape
(
1
,
1
),
output
[
0
].
reshape
(
1
,
1
),
""
,
1e-5
,
1.5e-4
);
normAssert
(
target
[
1
].
reshape
(
1
,
1
),
output
[
1
].
reshape
(
1
,
1
),
""
,
1e-5
,
3e-4
);
normAssert
(
target
[
2
].
reshape
(
1
,
1
),
output
[
2
].
reshape
(
1
,
1
),
""
,
4e-5
,
1e-2
);
}
OCL_TEST
(
Test_TensorFlow
,
Inception_v2_SSD
)
{
{
std
::
string
proto
=
findDataFile
(
"dnn/
ssd_inception_v2_coco_2017_11_17
.pbtxt"
,
false
);
std
::
string
proto
=
findDataFile
(
"dnn/
opencv_face_detector
.pbtxt"
,
false
);
std
::
string
model
=
findDataFile
(
"dnn/
ssd_inception_v2_coco_2017_11_17
.pb"
,
false
);
std
::
string
model
=
findDataFile
(
"dnn/
opencv_face_detector_uint8
.pb"
,
false
);
Net
net
=
readNetFromTensorflow
(
model
,
proto
);
Net
net
=
readNetFromTensorflow
(
model
,
proto
);
Mat
img
=
imread
(
findDataFile
(
"
dnn/street
.png"
,
false
));
Mat
img
=
imread
(
findDataFile
(
"
gpu/lbpcascade/er
.png"
,
false
));
Mat
blob
=
blobFromImage
(
img
,
1.0
f
/
127.5
,
Size
(
300
,
300
),
Scalar
(
127.5
,
127.5
,
127.5
),
tru
e
,
false
);
Mat
blob
=
blobFromImage
(
img
,
1.0
,
Size
(),
Scalar
(
104.0
,
177.0
,
123.0
),
fals
e
,
false
);
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
GetParam
());
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
net
.
setInput
(
blob
);
net
.
setInput
(
blob
);
// Output has shape 1x1xNx7 where N - number of detections.
// Output has shape 1x1xNx7 where N - number of detections.
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
Mat
out
=
net
.
forward
();
Mat
out
=
net
.
forward
();
out
=
out
.
reshape
(
1
,
out
.
total
()
/
7
);
Mat
detections
;
// References are from test for Caffe model.
for
(
int
i
=
0
;
i
<
out
.
rows
;
++
i
)
Mat
ref
=
(
Mat_
<
float
>
(
6
,
5
)
<<
0.99520785
,
0.80997437
,
0.16379407
,
0.87996572
,
0.26685631
,
{
0.9934696
,
0.2831718
,
0.50738752
,
0.345781
,
0.5985168
,
if
(
out
.
at
<
float
>
(
i
,
2
)
>
0.5
)
0.99096733
,
0.13629119
,
0.24892329
,
0.19756334
,
0.3310290
,
detections
.
push_back
(
out
.
row
(
i
).
colRange
(
1
,
7
));
0.98977017
,
0.23901358
,
0.09084064
,
0.29902688
,
0.1769477
,
}
0.97203469
,
0.67965847
,
0.06876482
,
0.73999709
,
0.1513494
,
0.95097077
,
0.51901293
,
0.45863652
,
0.5777427
,
0.5347801
);
normAssert
(
out
.
reshape
(
1
,
out
.
total
()
/
7
).
rowRange
(
0
,
6
).
colRange
(
2
,
7
),
ref
,
""
,
2.8e-4
,
3.4e-3
);
}
Mat
ref
=
(
Mat_
<
float
>
(
5
,
6
)
<<
1
,
0.90176028
,
0.19872092
,
0.36311883
,
0.26461923
,
0.63498729
,
INSTANTIATE_TEST_CASE_P
(
/**/
,
Test_TensorFlow_nets
,
availableDnnTargets
());
3
,
0.93569964
,
0.64865261
,
0.45906419
,
0.80675775
,
0.65708131
,
3
,
0.75838411
,
0.44668293
,
0.45907149
,
0.49459291
,
0.52197015
,
TEST
(
Test_TensorFlow
,
defun
)
10
,
0.95932811
,
0.38349164
,
0.32528657
,
0.40387636
,
0.39165527
,
{
10
,
0.93973452
,
0.66561931
,
0.37841269
,
0.68074018
,
0.42907384
);
runTensorFlowNet
(
"defun_dropout"
);
normAssert
(
detections
,
ref
);
}
TEST
(
Test_TensorFlow
,
fp16
)
{
const
float
l1
=
1e-3
;
const
float
lInf
=
1e-2
;
runTensorFlowNet
(
"fp16_single_conv"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_deconvolution"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_max_pool_odd_same"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_padding_valid"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_eltwise_add_mul"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_max_pool_odd_valid"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_pad_and_concat"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_max_pool_even"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
runTensorFlowNet
(
"fp16_padding_same"
,
DNN_TARGET_CPU
,
false
,
l1
,
lInf
);
}
TEST
(
Test_TensorFlow
,
quantized
)
{
runTensorFlowNet
(
"uint8_single_conv"
);
}
}
TEST
(
Test_TensorFlow
,
lstm
)
TEST
(
Test_TensorFlow
,
lstm
)
...
@@ -390,28 +343,4 @@ TEST(Test_TensorFlow, memory_read)
...
@@ -390,28 +343,4 @@ TEST(Test_TensorFlow, memory_read)
runTensorFlowNet
(
"batch_norm_text"
,
DNN_TARGET_CPU
,
true
,
l1
,
lInf
,
true
);
runTensorFlowNet
(
"batch_norm_text"
,
DNN_TARGET_CPU
,
true
,
l1
,
lInf
,
true
);
}
}
TEST
(
Test_TensorFlow
,
opencv_face_detector_uint8
)
{
std
::
string
proto
=
findDataFile
(
"dnn/opencv_face_detector.pbtxt"
,
false
);
std
::
string
model
=
findDataFile
(
"dnn/opencv_face_detector_uint8.pb"
,
false
);
Net
net
=
readNetFromTensorflow
(
model
,
proto
);
Mat
img
=
imread
(
findDataFile
(
"gpu/lbpcascade/er.png"
,
false
));
Mat
blob
=
blobFromImage
(
img
,
1.0
,
Size
(),
Scalar
(
104.0
,
177.0
,
123.0
),
false
,
false
);
net
.
setInput
(
blob
);
// Output has shape 1x1xNx7 where N - number of detections.
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
Mat
out
=
net
.
forward
();
// References are from test for Caffe model.
Mat
ref
=
(
Mat_
<
float
>
(
6
,
5
)
<<
0.99520785
,
0.80997437
,
0.16379407
,
0.87996572
,
0.26685631
,
0.9934696
,
0.2831718
,
0.50738752
,
0.345781
,
0.5985168
,
0.99096733
,
0.13629119
,
0.24892329
,
0.19756334
,
0.3310290
,
0.98977017
,
0.23901358
,
0.09084064
,
0.29902688
,
0.1769477
,
0.97203469
,
0.67965847
,
0.06876482
,
0.73999709
,
0.1513494
,
0.95097077
,
0.51901293
,
0.45863652
,
0.5777427
,
0.5347801
);
normAssert
(
out
.
reshape
(
1
,
out
.
total
()
/
7
).
rowRange
(
0
,
6
).
colRange
(
2
,
7
),
ref
,
""
,
2.8e-4
,
3.4e-3
);
}
}
}
modules/dnn/test/test_torch_importer.cpp
View file @
5b868ccd
...
@@ -42,7 +42,6 @@
...
@@ -42,7 +42,6 @@
#include "test_precomp.hpp"
#include "test_precomp.hpp"
#include "npy_blob.hpp"
#include "npy_blob.hpp"
#include <opencv2/dnn/shape_utils.hpp>
#include <opencv2/dnn/shape_utils.hpp>
#include <opencv2/ts/ocl_test.hpp>
namespace
opencv_test
namespace
opencv_test
{
{
...
@@ -100,219 +99,122 @@ static void runTorchNet(String prefix, int targetId = DNN_TARGET_CPU, String out
...
@@ -100,219 +99,122 @@ static void runTorchNet(String prefix, int targetId = DNN_TARGET_CPU, String out
}
}
}
}
TEST
(
Torch_Importer
,
run_convolution
)
typedef
testing
::
TestWithParam
<
DNNTarget
>
Test_Torch_layers
;
{
runTorchNet
(
"net_conv"
);
}
OCL_TEST
(
Torch_Importer
,
run_convolution
)
{
runTorchNet
(
"net_conv"
,
DNN_TARGET_OPENCL
);
}
TEST
(
Torch_Importer
,
run_pool_max
)
TEST
_P
(
Test_Torch_layers
,
run_convolution
)
{
{
runTorchNet
(
"net_
pool_max"
,
DNN_TARGET_CPU
,
""
,
true
);
runTorchNet
(
"net_
conv"
,
GetParam
()
);
}
}
OCL_TEST
(
Torch_Importer
,
run_pool_max
)
TEST_P
(
Test_Torch_layers
,
run_pool_max
)
{
{
runTorchNet
(
"net_pool_max"
,
DNN_TARGET_OPENCL
,
""
,
true
);
runTorchNet
(
"net_pool_max"
,
GetParam
()
,
""
,
true
);
}
}
TEST
(
Torch_Importer
,
run_pool_ave
)
TEST
_P
(
Test_Torch_layers
,
run_pool_ave
)
{
{
runTorchNet
(
"net_pool_ave"
);
runTorchNet
(
"net_pool_ave"
,
GetParam
()
);
}
}
OCL_TEST
(
Torch_Importer
,
run_pool_av
e
)
TEST_P
(
Test_Torch_layers
,
run_reshap
e
)
{
{
runTorchNet
(
"net_pool_ave"
,
DNN_TARGET_OPENCL
);
int
targetId
=
GetParam
();
runTorchNet
(
"net_reshape"
,
targetId
);
runTorchNet
(
"net_reshape_batch"
,
targetId
);
runTorchNet
(
"net_reshape_single_sample"
,
targetId
);
runTorchNet
(
"net_reshape_channels"
,
targetId
,
""
,
false
,
true
);
}
}
TEST
(
Torch_Importer
,
run_reshape
)
TEST
_P
(
Test_Torch_layers
,
run_linear
)
{
{
runTorchNet
(
"net_reshape"
);
runTorchNet
(
"net_linear_2d"
,
GetParam
());
runTorchNet
(
"net_reshape_batch"
);
runTorchNet
(
"net_reshape_single_sample"
);
runTorchNet
(
"net_reshape_channels"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
}
}
TEST
(
Torch_Importer
,
run_linear
)
TEST
_P
(
Test_Torch_layers
,
run_concat
)
{
{
runTorchNet
(
"net_linear_2d"
);
int
targetId
=
GetParam
();
runTorchNet
(
"net_concat"
,
targetId
,
"l5_torchMerge"
);
runTorchNet
(
"net_depth_concat"
,
targetId
,
""
,
false
,
true
);
}
}
TEST
(
Torch_Importer
,
run_paralel
)
TEST
_P
(
Test_Torch_layers
,
run_deconv
)
{
{
runTorchNet
(
"net_
parallel"
,
DNN_TARGET_CPU
,
"l5_torchMerge"
);
runTorchNet
(
"net_
deconv"
,
GetParam
()
);
}
}
TEST
(
Torch_Importer
,
run_concat
)
TEST
_P
(
Test_Torch_layers
,
run_batch_norm
)
{
{
runTorchNet
(
"net_concat"
,
DNN_TARGET_CPU
,
"l5_torchMerge"
);
runTorchNet
(
"net_batch_norm"
,
GetParam
(),
""
,
false
,
true
);
runTorchNet
(
"net_depth_concat"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
}
}
OCL_TEST
(
Torch_Importer
,
run_concat
)
TEST_P
(
Test_Torch_layers
,
net_prelu
)
{
{
runTorchNet
(
"net_concat"
,
DNN_TARGET_OPENCL
,
"l5_torchMerge"
);
runTorchNet
(
"net_prelu"
,
GetParam
());
runTorchNet
(
"net_depth_concat"
,
DNN_TARGET_OPENCL
,
""
,
false
,
true
);
}
}
TEST
(
Torch_Importer
,
run_deconv
)
TEST
_P
(
Test_Torch_layers
,
net_cadd_table
)
{
{
runTorchNet
(
"net_
deconv"
);
runTorchNet
(
"net_
cadd_table"
,
GetParam
()
);
}
}
OCL_TEST
(
Torch_Importer
,
run_deconv
)
TEST_P
(
Test_Torch_layers
,
net_softmax
)
{
{
runTorchNet
(
"net_deconv"
,
DNN_TARGET_OPENCL
);
int
targetId
=
GetParam
();
runTorchNet
(
"net_softmax"
,
targetId
);
runTorchNet
(
"net_softmax_spatial"
,
targetId
);
}
}
TEST
(
Torch_Importer
,
run_batch_norm
)
TEST_P
(
Test_Torch_layers
,
net_logsoftmax
)
{
runTorchNet
(
"net_batch_norm"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
}
OCL_TEST
(
Torch_Importer
,
run_batch_norm
)
{
runTorchNet
(
"net_batch_norm"
,
DNN_TARGET_OPENCL
,
""
,
false
,
true
);
}
TEST
(
Torch_Importer
,
net_prelu
)
{
runTorchNet
(
"net_prelu"
);
}
TEST
(
Torch_Importer
,
net_cadd_table
)
{
runTorchNet
(
"net_cadd_table"
);
}
TEST
(
Torch_Importer
,
net_softmax
)
{
runTorchNet
(
"net_softmax"
);
runTorchNet
(
"net_softmax_spatial"
);
}
OCL_TEST
(
Torch_Importer
,
net_softmax
)
{
runTorchNet
(
"net_softmax"
,
DNN_TARGET_OPENCL
);
runTorchNet
(
"net_softmax_spatial"
,
DNN_TARGET_OPENCL
);
}
TEST
(
Torch_Importer
,
net_logsoftmax
)
{
{
runTorchNet
(
"net_logsoftmax"
);
runTorchNet
(
"net_logsoftmax"
);
runTorchNet
(
"net_logsoftmax_spatial"
);
runTorchNet
(
"net_logsoftmax_spatial"
);
}
}
OCL_TEST
(
Torch_Importer
,
net_logsoftmax
)
TEST_P
(
Test_Torch_layers
,
net_lp_pooling
)
{
{
runTorchNet
(
"net_logsoftmax"
,
DNN_TARGET_OPENCL
);
int
targetId
=
GetParam
();
runTorchNet
(
"net_logsoftmax_spatial"
,
DNN_TARGET_OPENCL
);
runTorchNet
(
"net_lp_pooling_square"
,
targetId
,
""
,
false
,
true
);
runTorchNet
(
"net_lp_pooling_power"
,
targetId
,
""
,
false
,
true
);
}
}
TEST
(
Torch_Importer
,
net_lp_pooling
)
TEST
_P
(
Test_Torch_layers
,
net_conv_gemm_lrn
)
{
{
runTorchNet
(
"net_lp_pooling_square"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
runTorchNet
(
"net_conv_gemm_lrn"
,
GetParam
(),
""
,
false
,
true
);
runTorchNet
(
"net_lp_pooling_power"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
}
}
TEST
(
Torch_Importer
,
net_conv_gemm_lrn
)
TEST
_P
(
Test_Torch_layers
,
net_inception_block
)
{
{
runTorchNet
(
"net_
conv_gemm_lrn"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
runTorchNet
(
"net_
inception_block"
,
GetParam
()
,
""
,
false
,
true
);
}
}
TEST
(
Torch_Importer
,
net_inception_block
)
TEST
_P
(
Test_Torch_layers
,
net_normalize
)
{
{
runTorchNet
(
"net_
inception_block"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
runTorchNet
(
"net_
normalize"
,
GetParam
()
,
""
,
false
,
true
);
}
}
TEST
(
Torch_Importer
,
net_normalize
)
TEST
_P
(
Test_Torch_layers
,
net_padding
)
{
{
runTorchNet
(
"net_normalize"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
int
targetId
=
GetParam
();
runTorchNet
(
"net_padding"
,
targetId
,
""
,
false
,
true
);
runTorchNet
(
"net_spatial_zero_padding"
,
targetId
,
""
,
false
,
true
);
runTorchNet
(
"net_spatial_reflection_padding"
,
targetId
,
""
,
false
,
true
);
}
}
OCL_TEST
(
Torch_Importer
,
net_normalize
)
TEST_P
(
Test_Torch_layers
,
net_non_spatial
)
{
{
runTorchNet
(
"net_normalize"
,
DNN_TARGET_OPENCL
,
""
,
false
,
true
);
runTorchNet
(
"net_non_spatial"
,
GetParam
(),
""
,
false
,
true
);
}
TEST
(
Torch_Importer
,
net_padding
)
{
runTorchNet
(
"net_padding"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
runTorchNet
(
"net_spatial_zero_padding"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
runTorchNet
(
"net_spatial_reflection_padding"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
}
TEST
(
Torch_Importer
,
net_non_spatial
)
{
runTorchNet
(
"net_non_spatial"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
}
OCL_TEST
(
Torch_Importer
,
net_non_spatial
)
{
runTorchNet
(
"net_non_spatial"
,
DNN_TARGET_OPENCL
,
""
,
false
,
true
);
}
TEST
(
Torch_Importer
,
ENet_accuracy
)
{
Net
net
;
{
const
string
model
=
findDataFile
(
"dnn/Enet-model-best.net"
,
false
);
net
=
readNetFromTorch
(
model
,
true
);
ASSERT_FALSE
(
net
.
empty
());
}
Mat
sample
=
imread
(
_tf
(
"street.png"
,
false
));
Mat
inputBlob
=
blobFromImage
(
sample
,
1.
/
255
);
net
.
setInput
(
inputBlob
,
""
);
Mat
out
=
net
.
forward
();
Mat
ref
=
blobFromNPY
(
_tf
(
"torch_enet_prob.npy"
,
false
));
// Due to numerical instability in Pooling-Unpooling layers (indexes jittering)
// thresholds for ENet must be changed. Accuracy of resuults was checked on
// Cityscapes dataset and difference in mIOU with Torch is 10E-4%
normAssert
(
ref
,
out
,
""
,
0.00044
,
0.44
);
const
int
N
=
3
;
for
(
int
i
=
0
;
i
<
N
;
i
++
)
{
net
.
setInput
(
inputBlob
,
""
);
Mat
out
=
net
.
forward
();
normAssert
(
ref
,
out
,
""
,
0.00044
,
0.44
);
}
}
}
TEST
(
Torch_Importer
,
OpenFace_accuracy
)
INSTANTIATE_TEST_CASE_P
(
/**/
,
Test_Torch_layers
,
availableDnnTargets
());
{
const
string
model
=
findDataFile
(
"dnn/openface_nn4.small2.v1.t7"
,
false
);
Net
net
=
readNetFromTorch
(
model
);
Mat
sample
=
imread
(
findDataFile
(
"cv/shared/lena.png"
,
false
));
typedef
testing
::
TestWithParam
<
DNNTarget
>
Test_Torch_nets
;
Mat
sampleF32
(
sample
.
size
(),
CV_32FC3
);
sample
.
convertTo
(
sampleF32
,
sampleF32
.
type
());
sampleF32
/=
255
;
resize
(
sampleF32
,
sampleF32
,
Size
(
96
,
96
),
0
,
0
,
INTER_NEAREST
);
Mat
inputBlob
=
blobFromImage
(
sampleF32
);
net
.
setInput
(
inputBlob
);
TEST_P
(
Test_Torch_nets
,
OpenFace_accuracy
)
Mat
out
=
net
.
forward
();
Mat
outRef
=
readTorchBlob
(
_tf
(
"net_openface_output.dat"
),
true
);
normAssert
(
out
,
outRef
);
}
OCL_TEST
(
Torch_Importer
,
OpenFace_accuracy
)
{
{
const
string
model
=
findDataFile
(
"dnn/openface_nn4.small2.v1.t7"
,
false
);
const
string
model
=
findDataFile
(
"dnn/openface_nn4.small2.v1.t7"
,
false
);
Net
net
=
readNetFromTorch
(
model
);
Net
net
=
readNetFromTorch
(
model
);
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
GetParam
());
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
Mat
sample
=
imread
(
findDataFile
(
"cv/shared/lena.png"
,
false
));
Mat
sample
=
imread
(
findDataFile
(
"cv/shared/lena.png"
,
false
));
Mat
sampleF32
(
sample
.
size
(),
CV_32FC3
);
Mat
sampleF32
(
sample
.
size
(),
CV_32FC3
);
...
@@ -329,7 +231,7 @@ OCL_TEST(Torch_Importer, OpenFace_accuracy)
...
@@ -329,7 +231,7 @@ OCL_TEST(Torch_Importer, OpenFace_accuracy)
normAssert
(
out
,
outRef
);
normAssert
(
out
,
outRef
);
}
}
OCL_TEST
(
Torch_Importer
,
ENet_accuracy
)
TEST_P
(
Test_Torch_nets
,
ENet_accuracy
)
{
{
Net
net
;
Net
net
;
{
{
...
@@ -338,8 +240,7 @@ OCL_TEST(Torch_Importer, ENet_accuracy)
...
@@ -338,8 +240,7 @@ OCL_TEST(Torch_Importer, ENet_accuracy)
ASSERT_TRUE
(
!
net
.
empty
());
ASSERT_TRUE
(
!
net
.
empty
());
}
}
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
GetParam
());
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
Mat
sample
=
imread
(
_tf
(
"street.png"
,
false
));
Mat
sample
=
imread
(
_tf
(
"street.png"
,
false
));
Mat
inputBlob
=
blobFromImage
(
sample
,
1.
/
255
);
Mat
inputBlob
=
blobFromImage
(
sample
,
1.
/
255
);
...
@@ -374,7 +275,7 @@ OCL_TEST(Torch_Importer, ENet_accuracy)
...
@@ -374,7 +275,7 @@ OCL_TEST(Torch_Importer, ENet_accuracy)
// -median_filter 0 \
// -median_filter 0 \
// -image_size 0 \
// -image_size 0 \
// -model models/instance_norm/feathers.t7
// -model models/instance_norm/feathers.t7
TEST
(
Torch_Importer
,
FastNeuralStyle_accuracy
)
TEST
_P
(
Test_Torch_nets
,
FastNeuralStyle_accuracy
)
{
{
std
::
string
models
[]
=
{
"dnn/fast_neural_style_eccv16_starry_night.t7"
,
std
::
string
models
[]
=
{
"dnn/fast_neural_style_eccv16_starry_night.t7"
,
"dnn/fast_neural_style_instance_norm_feathers.t7"
};
"dnn/fast_neural_style_instance_norm_feathers.t7"
};
...
@@ -385,6 +286,8 @@ TEST(Torch_Importer, FastNeuralStyle_accuracy)
...
@@ -385,6 +286,8 @@ TEST(Torch_Importer, FastNeuralStyle_accuracy)
const
string
model
=
findDataFile
(
models
[
i
],
false
);
const
string
model
=
findDataFile
(
models
[
i
],
false
);
Net
net
=
readNetFromTorch
(
model
);
Net
net
=
readNetFromTorch
(
model
);
net
.
setPreferableTarget
(
GetParam
());
Mat
img
=
imread
(
findDataFile
(
"dnn/googlenet_1.png"
,
false
));
Mat
img
=
imread
(
findDataFile
(
"dnn/googlenet_1.png"
,
false
));
Mat
inputBlob
=
blobFromImage
(
img
,
1.0
,
Size
(),
Scalar
(
103.939
,
116.779
,
123.68
),
false
);
Mat
inputBlob
=
blobFromImage
(
img
,
1.0
,
Size
(),
Scalar
(
103.939
,
116.779
,
123.68
),
false
);
...
@@ -404,37 +307,17 @@ TEST(Torch_Importer, FastNeuralStyle_accuracy)
...
@@ -404,37 +307,17 @@ TEST(Torch_Importer, FastNeuralStyle_accuracy)
}
}
}
}
OCL_TEST
(
Torch_Importer
,
FastNeuralStyle_accuracy
)
INSTANTIATE_TEST_CASE_P
(
/**/
,
Test_Torch_nets
,
availableDnnTargets
());
{
std
::
string
models
[]
=
{
"dnn/fast_neural_style_eccv16_starry_night.t7"
,
"dnn/fast_neural_style_instance_norm_feathers.t7"
};
std
::
string
targets
[]
=
{
"dnn/lena_starry_night.png"
,
"dnn/lena_feathers.png"
};
for
(
int
i
=
0
;
i
<
2
;
++
i
)
// TODO: fix OpenCL and add to the rest of tests
{
TEST
(
Torch_Importer
,
run_paralel
)
const
string
model
=
findDataFile
(
models
[
i
],
false
);
{
Net
net
=
readNetFromTorch
(
model
);
runTorchNet
(
"net_parallel"
,
DNN_TARGET_CPU
,
"l5_torchMerge"
);
}
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
Mat
img
=
imread
(
findDataFile
(
"dnn/googlenet_1.png"
,
false
));
Mat
inputBlob
=
blobFromImage
(
img
,
1.0
,
Size
(),
Scalar
(
103.939
,
116.779
,
123.68
),
false
);
net
.
setInput
(
inputBlob
);
Mat
out
=
net
.
forward
();
// Deprocessing.
getPlane
(
out
,
0
,
0
)
+=
103.939
;
getPlane
(
out
,
0
,
1
)
+=
116.779
;
getPlane
(
out
,
0
,
2
)
+=
123.68
;
out
=
cv
::
min
(
cv
::
max
(
0
,
out
),
255
);
Mat
ref
=
imread
(
findDataFile
(
targets
[
i
]));
Mat
refBlob
=
blobFromImage
(
ref
,
1.0
,
Size
(),
Scalar
(),
false
);
normAssert
(
out
,
refBlob
,
""
,
0.5
,
1.1
);
TEST
(
Torch_Importer
,
DISABLED_run_paralel
)
}
{
runTorchNet
(
"net_parallel"
,
DNN_TARGET_OPENCL
,
"l5_torchMerge"
);
}
}
}
}
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