Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
5b868ccd
O
Opencv
项目概览
Greenplum
/
Opencv
大约 1 年 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
5b868ccd
编写于
3月 09, 2018
作者:
A
Alexander Alekhin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #10992 from dkurt:dnn_opencl_tests
上级
687394fa
0f01b40d
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
258 addition
and
476 deletion
+258
-476
modules/dnn/src/layers/convolution_layer.cpp
modules/dnn/src/layers/convolution_layer.cpp
+3
-0
modules/dnn/src/layers/fully_connected_layer.cpp
modules/dnn/src/layers/fully_connected_layer.cpp
+5
-0
modules/dnn/src/layers/lrn_layer.cpp
modules/dnn/src/layers/lrn_layer.cpp
+5
-0
modules/dnn/src/layers/pooling_layer.cpp
modules/dnn/src/layers/pooling_layer.cpp
+4
-0
modules/dnn/src/layers/softmax_layer.cpp
modules/dnn/src/layers/softmax_layer.cpp
+5
-0
modules/dnn/test/test_backends.cpp
modules/dnn/test/test_backends.cpp
+0
-3
modules/dnn/test/test_caffe_importer.cpp
modules/dnn/test/test_caffe_importer.cpp
+50
-122
modules/dnn/test/test_googlenet.cpp
modules/dnn/test/test_googlenet.cpp
+4
-0
modules/dnn/test/test_precomp.hpp
modules/dnn/test/test_precomp.hpp
+19
-0
modules/dnn/test/test_tf_importer.cpp
modules/dnn/test/test_tf_importer.cpp
+96
-167
modules/dnn/test/test_torch_importer.cpp
modules/dnn/test/test_torch_importer.cpp
+67
-184
未找到文件。
modules/dnn/src/layers/convolution_layer.cpp
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
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
浏览文件 @
5b868ccd
...
...
@@ -11,8 +11,6 @@ Test for Tensorflow models loading
#include "test_precomp.hpp"
#include "npy_blob.hpp"
#include <opencv2/core/ocl.hpp>
#include <opencv2/ts/ocl_test.hpp>
namespace
opencv_test
{
...
...
@@ -115,118 +113,85 @@ static void runTensorFlowNet(const std::string& prefix, int targetId = DNN_TARGE
normAssert
(
target
,
output
,
""
,
l1
,
lInf
);
}
TEST
(
Test_TensorFlow
,
conv
)
{
runTensorFlowNet
(
"single_conv"
);
runTensorFlowNet
(
"atrous_conv2d_valid"
);
runTensorFlowNet
(
"atrous_conv2d_same"
);
runTensorFlowNet
(
"depthwise_conv2d"
);
}
typedef
testing
::
TestWithParam
<
DNNTarget
>
Test_TensorFlow_layers
;
TEST
(
Test_TensorFlow
,
padding
)
TEST
_P
(
Test_TensorFlow_layers
,
conv
)
{
runTensorFlowNet
(
"padding_same"
);
runTensorFlowNet
(
"padding_valid"
);
runTensorFlowNet
(
"spatial_padding"
);
int
targetId
=
GetParam
();
runTensorFlowNet
(
"single_conv"
,
targetId
);
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"
);
runTensorFlowNet
(
"fused_batch_norm"
);
runTensorFlowNet
(
"batch_norm_text"
,
DNN_TARGET_CPU
,
true
);
runTensorFlowNet
(
"mvn_batch_norm"
);
runTensorFlowNet
(
"mvn_batch_norm_1x1"
);
int
targetId
=
GetParam
();
runTensorFlowNet
(
"batch_norm"
,
targetId
);
runTensorFlowNet
(
"fused_batch_norm"
,
targetId
);
runTensorFlowNet
(
"batch_norm_text"
,
targetId
,
true
);
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
);
runTensorFlowNet
(
"fused_batch_norm"
,
DNN_TARGET_OPENCL
);
runTensorFlowNet
(
"batch_norm_text"
,
DNN_TARGET_OPENCL
,
true
);
int
targetId
=
GetParam
();
runTensorFlowNet
(
"max_pool_even"
,
targetId
);
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"
);
runTensorFlowNet
(
"max_pool_odd_valid"
);
runTensorFlowNet
(
"max_pool_odd_same"
);
runTensorFlowNet
(
"ave_pool_same"
);
int
targetId
=
GetParam
();
runTensorFlowNet
(
"deconvolution"
,
targetId
);
runTensorFlowNet
(
"deconvolution_same"
,
targetId
);
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"
);
runTensorFlowNet
(
"deconvolution_same"
);
runTensorFlowNet
(
"deconvolution_stride_2_same"
);
runTensorFlowNet
(
"deconvolution_adj_pad_valid"
);
runTensorFlowNet
(
"deconvolution_adj_pad_same"
);
int
targetId
=
GetParam
();
runTensorFlowNet
(
"matmul"
,
targetId
);
runTensorFlowNet
(
"nhwc_reshape_matmul"
,
targetId
);
runTensorFlowNet
(
"nhwc_transpose_reshape_matmul"
,
targetId
);
}
OCL_TEST
(
Test_TensorFlow
,
deconvolution
)
TEST_P
(
Test_TensorFlow_layers
,
reshape
)
{
runTensorFlowNet
(
"deconvolution"
,
DNN_TARGET_OPENCL
);
runTensorFlowNet
(
"deconvolution_same"
,
DNN_TARGET_OPENCL
);
runTensorFlowNet
(
"deconvolution_stride_2_same"
,
DNN_TARGET_OPENCL
);
runTensorFlowNet
(
"deconvolution_adj_pad_valid"
,
DNN_TARGET_OPENCL
);
runTensorFlowNet
(
"deconvolution_adj_pad_same"
,
DNN_TARGET_OPENCL
);
int
targetId
=
GetParam
();
runTensorFlowNet
(
"shift_reshape_no_reorder"
,
targetId
);
runTensorFlowNet
(
"reshape_reduce"
,
targetId
);
runTensorFlowNet
(
"flatten"
,
targetId
,
true
);
}
TEST
(
Test_TensorFlow
,
matmul
)
{
runTensorFlowNet
(
"matmul"
);
runTensorFlowNet
(
"nhwc_reshape_matmul"
);
runTensorFlowNet
(
"nhwc_transpose_reshape_matmul"
);
}
INSTANTIATE_TEST_CASE_P
(
/**/
,
Test_TensorFlow_layers
,
availableDnnTargets
());
TEST
(
Test_TensorFlow
,
defun
)
{
runTensorFlowNet
(
"defun_dropout"
);
}
typedef
testing
::
TestWithParam
<
DNNTarget
>
Test_TensorFlow_nets
;
TEST
(
Test_TensorFlow
,
reshape
)
{
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
)
TEST_P
(
Test_TensorFlow_nets
,
MobileNet_SSD
)
{
std
::
string
netPath
=
findDataFile
(
"dnn/ssd_mobilenet_v1_coco.pb"
,
false
);
std
::
string
netConfig
=
findDataFile
(
"dnn/ssd_mobilenet_v1_coco.pbtxt"
,
false
);
...
...
@@ -249,17 +214,20 @@ TEST(Test_TensorFlow, MobileNet_SSD)
}
Net
net
=
readNetFromTensorflow
(
netPath
,
netConfig
);
net
.
setPreferableTarget
(
GetParam
());
net
.
setInput
(
inp
);
std
::
vector
<
Mat
>
output
;
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
[
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
model
=
findDataFile
(
"dnn/ssd_inception_v2_coco_2017_11_17.pb"
,
false
);
...
...
@@ -268,6 +236,8 @@ TEST(Test_TensorFlow, Inception_v2_SSD)
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
);
net
.
setPreferableTarget
(
GetParam
());
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]
...
...
@@ -289,74 +259,57 @@ TEST(Test_TensorFlow, Inception_v2_SSD)
normAssert
(
detections
,
ref
);
}
OCL_TEST
(
Test_TensorFlow
,
MobileNet_SSD
)
{
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
)
TEST_P
(
Test_TensorFlow_nets
,
opencv_face_detector_uint8
)
{
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
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
(
"
dnn/street
.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
img
=
imread
(
findDataFile
(
"
gpu/lbpcascade/er
.png"
,
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
(
DNN_TARGET_OPENCL
);
net
.
setPreferableTarget
(
GetParam
());
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
();
out
=
out
.
reshape
(
1
,
out
.
total
()
/
7
);
Mat
detections
;
for
(
int
i
=
0
;
i
<
out
.
rows
;
++
i
)
{
if
(
out
.
at
<
float
>
(
i
,
2
)
>
0.5
)
detections
.
push_back
(
out
.
row
(
i
).
colRange
(
1
,
7
));
}
// 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
);
}
Mat
ref
=
(
Mat_
<
float
>
(
5
,
6
)
<<
1
,
0.90176028
,
0.19872092
,
0.36311883
,
0.26461923
,
0.63498729
,
3
,
0.93569964
,
0.64865261
,
0.45906419
,
0.80675775
,
0.65708131
,
3
,
0.75838411
,
0.44668293
,
0.45907149
,
0.49459291
,
0.52197015
,
10
,
0.95932811
,
0.38349164
,
0.32528657
,
0.40387636
,
0.39165527
,
10
,
0.93973452
,
0.66561931
,
0.37841269
,
0.68074018
,
0.42907384
);
normAssert
(
detections
,
ref
);
INSTANTIATE_TEST_CASE_P
(
/**/
,
Test_TensorFlow_nets
,
availableDnnTargets
());
TEST
(
Test_TensorFlow
,
defun
)
{
runTensorFlowNet
(
"defun_dropout"
);
}
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
)
...
...
@@ -390,28 +343,4 @@ TEST(Test_TensorFlow, memory_read)
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
浏览文件 @
5b868ccd
...
...
@@ -42,7 +42,6 @@
#include "test_precomp.hpp"
#include "npy_blob.hpp"
#include <opencv2/dnn/shape_utils.hpp>
#include <opencv2/ts/ocl_test.hpp>
namespace
opencv_test
{
...
...
@@ -100,219 +99,122 @@ static void runTorchNet(String prefix, int targetId = DNN_TARGET_CPU, String out
}
}
TEST
(
Torch_Importer
,
run_convolution
)
{
runTorchNet
(
"net_conv"
);
}
OCL_TEST
(
Torch_Importer
,
run_convolution
)
{
runTorchNet
(
"net_conv"
,
DNN_TARGET_OPENCL
);
}
TEST
(
Torch_Importer
,
run_pool_max
)
{
runTorchNet
(
"net_pool_max"
,
DNN_TARGET_CPU
,
""
,
true
);
}
OCL_TEST
(
Torch_Importer
,
run_pool_max
)
{
runTorchNet
(
"net_pool_max"
,
DNN_TARGET_OPENCL
,
""
,
true
);
}
TEST
(
Torch_Importer
,
run_pool_ave
)
{
runTorchNet
(
"net_pool_ave"
);
}
typedef
testing
::
TestWithParam
<
DNNTarget
>
Test_Torch_layers
;
OCL_TEST
(
Torch_Importer
,
run_pool_ave
)
TEST_P
(
Test_Torch_layers
,
run_convolution
)
{
runTorchNet
(
"net_
pool_ave"
,
DNN_TARGET_OPENCL
);
runTorchNet
(
"net_
conv"
,
GetParam
()
);
}
TEST
(
Torch_Importer
,
run_reshape
)
TEST
_P
(
Test_Torch_layers
,
run_pool_max
)
{
runTorchNet
(
"net_reshape"
);
runTorchNet
(
"net_reshape_batch"
);
runTorchNet
(
"net_reshape_single_sample"
);
runTorchNet
(
"net_reshape_channels"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
runTorchNet
(
"net_pool_max"
,
GetParam
(),
""
,
true
);
}
TEST
(
Torch_Importer
,
run_linear
)
TEST
_P
(
Test_Torch_layers
,
run_pool_ave
)
{
runTorchNet
(
"net_
linear_2d"
);
runTorchNet
(
"net_
pool_ave"
,
GetParam
()
);
}
TEST
(
Torch_Importer
,
run_paralel
)
{
runTorchNet
(
"net_parallel"
,
DNN_TARGET_CPU
,
"l5_torchMerge"
);
}
TEST
(
Torch_Importer
,
run_concat
)
{
runTorchNet
(
"net_concat"
,
DNN_TARGET_CPU
,
"l5_torchMerge"
);
runTorchNet
(
"net_depth_concat"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
}
OCL_TEST
(
Torch_Importer
,
run_concat
)
{
runTorchNet
(
"net_concat"
,
DNN_TARGET_OPENCL
,
"l5_torchMerge"
);
runTorchNet
(
"net_depth_concat"
,
DNN_TARGET_OPENCL
,
""
,
false
,
true
);
}
TEST
(
Torch_Importer
,
run_deconv
)
TEST_P
(
Test_Torch_layers
,
run_reshape
)
{
runTorchNet
(
"net_deconv"
);
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
);
}
OCL_TEST
(
Torch_Importer
,
run_deconv
)
TEST_P
(
Test_Torch_layers
,
run_linear
)
{
runTorchNet
(
"net_
deconv"
,
DNN_TARGET_OPENCL
);
runTorchNet
(
"net_
linear_2d"
,
GetParam
()
);
}
TEST
(
Torch_Importer
,
run_batch_norm
)
TEST
_P
(
Test_Torch_layers
,
run_concat
)
{
runTorchNet
(
"net_batch_norm"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
int
targetId
=
GetParam
();
runTorchNet
(
"net_concat"
,
targetId
,
"l5_torchMerge"
);
runTorchNet
(
"net_depth_concat"
,
targetId
,
""
,
false
,
true
);
}
OCL_TEST
(
Torch_Importer
,
run_batch_norm
)
TEST_P
(
Test_Torch_layers
,
run_deconv
)
{
runTorchNet
(
"net_
batch_norm"
,
DNN_TARGET_OPENCL
,
""
,
false
,
true
);
runTorchNet
(
"net_
deconv"
,
GetParam
()
);
}
TEST
(
Torch_Importer
,
net_prelu
)
TEST
_P
(
Test_Torch_layers
,
run_batch_norm
)
{
runTorchNet
(
"net_
prelu"
);
runTorchNet
(
"net_
batch_norm"
,
GetParam
(),
""
,
false
,
true
);
}
TEST
(
Torch_Importer
,
net_cadd_table
)
TEST
_P
(
Test_Torch_layers
,
net_prelu
)
{
runTorchNet
(
"net_
cadd_table"
);
runTorchNet
(
"net_
prelu"
,
GetParam
()
);
}
TEST
(
Torch_Importer
,
net_softmax
)
TEST
_P
(
Test_Torch_layers
,
net_cadd_table
)
{
runTorchNet
(
"net_softmax"
);
runTorchNet
(
"net_softmax_spatial"
);
runTorchNet
(
"net_cadd_table"
,
GetParam
());
}
OCL_TEST
(
Torch_Importer
,
net_softmax
)
TEST_P
(
Test_Torch_layers
,
net_softmax
)
{
runTorchNet
(
"net_softmax"
,
DNN_TARGET_OPENCL
);
runTorchNet
(
"net_softmax_spatial"
,
DNN_TARGET_OPENCL
);
int
targetId
=
GetParam
();
runTorchNet
(
"net_softmax"
,
targetId
);
runTorchNet
(
"net_softmax_spatial"
,
targetId
);
}
TEST
(
Torch_Importer
,
net_logsoftmax
)
TEST
_P
(
Test_Torch_layers
,
net_logsoftmax
)
{
runTorchNet
(
"net_logsoftmax"
);
runTorchNet
(
"net_logsoftmax_spatial"
);
}
OCL_TEST
(
Torch_Importer
,
net_logsoftmax
)
{
runTorchNet
(
"net_logsoftmax"
,
DNN_TARGET_OPENCL
);
runTorchNet
(
"net_logsoftmax_spatial"
,
DNN_TARGET_OPENCL
);
}
TEST
(
Torch_Importer
,
net_lp_pooling
)
TEST_P
(
Test_Torch_layers
,
net_lp_pooling
)
{
runTorchNet
(
"net_lp_pooling_square"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
runTorchNet
(
"net_lp_pooling_power"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
int
targetId
=
GetParam
();
runTorchNet
(
"net_lp_pooling_square"
,
targetId
,
""
,
false
,
true
);
runTorchNet
(
"net_lp_pooling_power"
,
targetId
,
""
,
false
,
true
);
}
TEST
(
Torch_Importer
,
net_conv_gemm_lrn
)
TEST
_P
(
Test_Torch_layers
,
net_conv_gemm_lrn
)
{
runTorchNet
(
"net_conv_gemm_lrn"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
runTorchNet
(
"net_conv_gemm_lrn"
,
GetParam
()
,
""
,
false
,
true
);
}
TEST
(
Torch_Importer
,
net_inception_block
)
TEST
_P
(
Test_Torch_layers
,
net_inception_block
)
{
runTorchNet
(
"net_inception_block"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
runTorchNet
(
"net_inception_block"
,
GetParam
()
,
""
,
false
,
true
);
}
TEST
(
Torch_Importer
,
net_normalize
)
TEST
_P
(
Test_Torch_layers
,
net_normalize
)
{
runTorchNet
(
"net_normalize"
,
DNN_TARGET_CPU
,
""
,
false
,
true
);
runTorchNet
(
"net_normalize"
,
GetParam
()
,
""
,
false
,
true
);
}
OCL_TEST
(
Torch_Importer
,
net_normalize
)
TEST_P
(
Test_Torch_layers
,
net_padding
)
{
runTorchNet
(
"net_normalize"
,
DNN_TARGET_OPENCL
,
""
,
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
);
}
TEST
(
Torch_Importer
,
net_padding
)
TEST
_P
(
Test_Torch_layers
,
net_non_spatial
)
{
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
);
}
runTorchNet
(
"net_non_spatial"
,
GetParam
(),
""
,
false
,
true
);
}
TEST
(
Torch_Importer
,
OpenFace_accuracy
)
{
const
string
model
=
findDataFile
(
"dnn/openface_nn4.small2.v1.t7"
,
false
);
Net
net
=
readNetFromTorch
(
model
);
Mat
sample
=
imread
(
findDataFile
(
"cv/shared/lena.png"
,
false
));
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
);
INSTANTIATE_TEST_CASE_P
(
/**/
,
Test_Torch_layers
,
availableDnnTargets
());
net
.
setInput
(
inputBlob
);
Mat
out
=
net
.
forward
();
Mat
outRef
=
readTorchBlob
(
_tf
(
"net_openface_output.dat"
),
true
);
normAssert
(
out
,
outRef
);
}
typedef
testing
::
TestWithParam
<
DNNTarget
>
Test_Torch_nets
;
OCL_TEST
(
Torch_Importer
,
OpenFace_accuracy
)
TEST_P
(
Test_Torch_nets
,
OpenFace_accuracy
)
{
const
string
model
=
findDataFile
(
"dnn/openface_nn4.small2.v1.t7"
,
false
);
Net
net
=
readNetFromTorch
(
model
);
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
net
.
setPreferableTarget
(
GetParam
());
Mat
sample
=
imread
(
findDataFile
(
"cv/shared/lena.png"
,
false
));
Mat
sampleF32
(
sample
.
size
(),
CV_32FC3
);
...
...
@@ -329,7 +231,7 @@ OCL_TEST(Torch_Importer, OpenFace_accuracy)
normAssert
(
out
,
outRef
);
}
OCL_TEST
(
Torch_Importer
,
ENet_accuracy
)
TEST_P
(
Test_Torch_nets
,
ENet_accuracy
)
{
Net
net
;
{
...
...
@@ -338,8 +240,7 @@ OCL_TEST(Torch_Importer, ENet_accuracy)
ASSERT_TRUE
(
!
net
.
empty
());
}
net
.
setPreferableBackend
(
DNN_BACKEND_DEFAULT
);
net
.
setPreferableTarget
(
DNN_TARGET_OPENCL
);
net
.
setPreferableTarget
(
GetParam
());
Mat
sample
=
imread
(
_tf
(
"street.png"
,
false
));
Mat
inputBlob
=
blobFromImage
(
sample
,
1.
/
255
);
...
...
@@ -374,7 +275,7 @@ OCL_TEST(Torch_Importer, ENet_accuracy)
// -median_filter 0 \
// -image_size 0 \
// -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"
,
"dnn/fast_neural_style_instance_norm_feathers.t7"
};
...
...
@@ -385,6 +286,8 @@ TEST(Torch_Importer, FastNeuralStyle_accuracy)
const
string
model
=
findDataFile
(
models
[
i
],
false
);
Net
net
=
readNetFromTorch
(
model
);
net
.
setPreferableTarget
(
GetParam
());
Mat
img
=
imread
(
findDataFile
(
"dnn/googlenet_1.png"
,
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)
}
}
OCL_TEST
(
Torch_Importer
,
FastNeuralStyle_accuracy
)
{
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
)
{
const
string
model
=
findDataFile
(
models
[
i
],
false
);
Net
net
=
readNetFromTorch
(
model
);
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
);
INSTANTIATE_TEST_CASE_P
(
/**/
,
Test_Torch_nets
,
availableDnnTargets
());
Mat
ref
=
imread
(
findDataFile
(
targets
[
i
]));
Mat
refBlob
=
blobFromImage
(
ref
,
1.0
,
Size
(),
Scalar
(),
false
);
// TODO: fix OpenCL and add to the rest of tests
TEST
(
Torch_Importer
,
run_paralel
)
{
runTorchNet
(
"net_parallel"
,
DNN_TARGET_CPU
,
"l5_torchMerge"
);
}
normAssert
(
out
,
refBlob
,
""
,
0.5
,
1.1
);
}
TEST
(
Torch_Importer
,
DISABLED_run_paralel
)
{
runTorchNet
(
"net_parallel"
,
DNN_TARGET_OPENCL
,
"l5_torchMerge"
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录