Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
236f3839
O
Opencv
项目概览
Greenplum
/
Opencv
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
236f3839
编写于
7月 24, 2018
作者:
A
Alexander Alekhin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #12037 from dkurt:test_openvino_models
上级
93abdbf2
4283309d
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
278 addition
and
11 deletion
+278
-11
modules/dnn/CMakeLists.txt
modules/dnn/CMakeLists.txt
+6
-0
modules/dnn/src/op_inf_engine.cpp
modules/dnn/src/op_inf_engine.cpp
+3
-4
modules/dnn/test/test_ie_models.cpp
modules/dnn/test/test_ie_models.cpp
+238
-0
modules/ts/include/opencv2/ts.hpp
modules/ts/include/opencv2/ts.hpp
+6
-0
modules/ts/src/ts.cpp
modules/ts/src/ts.cpp
+25
-7
未找到文件。
modules/dnn/CMakeLists.txt
浏览文件 @
236f3839
...
...
@@ -120,3 +120,9 @@ if(BUILD_PERF_TESTS)
endif
()
endif
()
endif
()
# Test Intel's Inference Engine models
if
(
HAVE_INF_ENGINE AND TARGET opencv_test_dnn
)
ocv_target_include_directories
(
opencv_test_dnn PRIVATE
${
INF_ENGINE_INCLUDE_DIRS
}
)
ocv_target_link_libraries
(
opencv_test_dnn LINK_PRIVATE
${
INF_ENGINE_LIBRARIES
}
)
endif
()
modules/dnn/src/op_inf_engine.cpp
浏览文件 @
236f3839
...
...
@@ -428,9 +428,8 @@ void InfEngineBackendNet::initPlugin(InferenceEngine::ICNNNetwork& net)
try
{
static
std
::
map
<
std
::
string
,
InferenceEngine
::
InferenceEnginePluginPtr
>
sharedPlugins
;
std
::
string
deviceName
=
InferenceEngine
::
getDeviceName
(
targetDevice
);
auto
pluginIt
=
sharedPlugins
.
find
(
deviceName
);
static
std
::
map
<
InferenceEngine
::
TargetDevice
,
InferenceEngine
::
InferenceEnginePluginPtr
>
sharedPlugins
;
auto
pluginIt
=
sharedPlugins
.
find
(
targetDevice
);
if
(
pluginIt
!=
sharedPlugins
.
end
())
{
enginePtr
=
pluginIt
->
second
;
...
...
@@ -438,7 +437,7 @@ void InfEngineBackendNet::initPlugin(InferenceEngine::ICNNNetwork& net)
else
{
enginePtr
=
InferenceEngine
::
PluginDispatcher
({
""
}).
getSuitablePlugin
(
targetDevice
);
sharedPlugins
[
deviceNam
e
]
=
enginePtr
;
sharedPlugins
[
targetDevic
e
]
=
enginePtr
;
if
(
targetDevice
==
InferenceEngine
::
TargetDevice
::
eCPU
)
{
...
...
modules/dnn/test/test_ie_models.cpp
0 → 100644
浏览文件 @
236f3839
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
//
// Copyright (C) 2018, Intel Corporation, all rights reserved.
// Third party copyrights are property of their respective owners.
#include "test_precomp.hpp"
#ifdef HAVE_INF_ENGINE
#include <opencv2/core/utils/filesystem.hpp>
#include <inference_engine.hpp>
#include <ie_icnn_network.hpp>
#include <ie_extension.h>
namespace
opencv_test
{
namespace
{
static
void
initDLDTDataPath
()
{
#ifndef WINRT
static
bool
initialized
=
false
;
if
(
!
initialized
)
{
const
char
*
dldtTestDataPath
=
getenv
(
"INTEL_CVSDK_DIR"
);
if
(
dldtTestDataPath
)
cvtest
::
addDataSearchPath
(
cv
::
utils
::
fs
::
join
(
dldtTestDataPath
,
"deployment_tools"
));
initialized
=
true
;
}
#endif
}
using
namespace
cv
;
using
namespace
cv
::
dnn
;
using
namespace
InferenceEngine
;
static
inline
void
genData
(
const
std
::
vector
<
size_t
>&
dims
,
Mat
&
m
,
Blob
::
Ptr
&
dataPtr
)
{
std
::
vector
<
int
>
reversedDims
(
dims
.
begin
(),
dims
.
end
());
std
::
reverse
(
reversedDims
.
begin
(),
reversedDims
.
end
());
m
.
create
(
reversedDims
,
CV_32F
);
randu
(
m
,
-
1
,
1
);
dataPtr
=
make_shared_blob
<
float
>
(
Precision
::
FP32
,
dims
,
(
float
*
)
m
.
data
);
}
void
runIE
(
Target
target
,
const
std
::
string
&
xmlPath
,
const
std
::
string
&
binPath
,
std
::
map
<
std
::
string
,
cv
::
Mat
>&
inputsMap
,
std
::
map
<
std
::
string
,
cv
::
Mat
>&
outputsMap
)
{
CNNNetReader
reader
;
reader
.
ReadNetwork
(
xmlPath
);
reader
.
ReadWeights
(
binPath
);
CNNNetwork
net
=
reader
.
getNetwork
();
InferenceEnginePluginPtr
enginePtr
;
InferencePlugin
plugin
;
ExecutableNetwork
netExec
;
InferRequest
infRequest
;
TargetDevice
targetDevice
;
switch
(
target
)
{
case
DNN_TARGET_CPU
:
targetDevice
=
TargetDevice
::
eCPU
;
break
;
case
DNN_TARGET_OPENCL
:
case
DNN_TARGET_OPENCL_FP16
:
targetDevice
=
TargetDevice
::
eGPU
;
break
;
case
DNN_TARGET_MYRIAD
:
targetDevice
=
TargetDevice
::
eMYRIAD
;
break
;
default:
CV_Error
(
Error
::
StsNotImplemented
,
"Unknown target"
);
};
try
{
enginePtr
=
PluginDispatcher
({
""
}).
getSuitablePlugin
(
targetDevice
);
if
(
targetDevice
==
TargetDevice
::
eCPU
)
{
std
::
string
suffixes
[]
=
{
"_avx2"
,
"_sse4"
,
""
};
bool
haveFeature
[]
=
{
checkHardwareSupport
(
CPU_AVX2
),
checkHardwareSupport
(
CPU_SSE4_2
),
true
};
for
(
int
i
=
0
;
i
<
3
;
++
i
)
{
if
(
!
haveFeature
[
i
])
continue
;
#ifdef _WIN32
std
::
string
libName
=
"cpu_extension"
+
suffixes
[
i
]
+
".dll"
;
#else
std
::
string
libName
=
"libcpu_extension"
+
suffixes
[
i
]
+
".so"
;
#endif // _WIN32
try
{
IExtensionPtr
extension
=
make_so_pointer
<
IExtension
>
(
libName
);
enginePtr
->
AddExtension
(
extension
,
0
);
break
;
}
catch
(...)
{}
}
// Some of networks can work without a library of extra layers.
}
plugin
=
InferencePlugin
(
enginePtr
);
netExec
=
plugin
.
LoadNetwork
(
net
,
{});
infRequest
=
netExec
.
CreateInferRequest
();
}
catch
(
const
std
::
exception
&
ex
)
{
CV_Error
(
Error
::
StsAssert
,
format
(
"Failed to initialize Inference Engine backend: %s"
,
ex
.
what
()));
}
// Fill input blobs.
inputsMap
.
clear
();
BlobMap
inputBlobs
;
for
(
auto
&
it
:
net
.
getInputsInfo
())
{
genData
(
it
.
second
->
getDims
(),
inputsMap
[
it
.
first
],
inputBlobs
[
it
.
first
]);
}
infRequest
.
SetInput
(
inputBlobs
);
// Fill output blobs.
outputsMap
.
clear
();
BlobMap
outputBlobs
;
for
(
auto
&
it
:
net
.
getOutputsInfo
())
{
genData
(
it
.
second
->
dims
,
outputsMap
[
it
.
first
],
outputBlobs
[
it
.
first
]);
}
infRequest
.
SetOutput
(
outputBlobs
);
infRequest
.
Infer
();
}
std
::
vector
<
String
>
getOutputsNames
(
const
Net
&
net
)
{
std
::
vector
<
String
>
names
;
if
(
names
.
empty
())
{
std
::
vector
<
int
>
outLayers
=
net
.
getUnconnectedOutLayers
();
std
::
vector
<
String
>
layersNames
=
net
.
getLayerNames
();
names
.
resize
(
outLayers
.
size
());
for
(
size_t
i
=
0
;
i
<
outLayers
.
size
();
++
i
)
names
[
i
]
=
layersNames
[
outLayers
[
i
]
-
1
];
}
return
names
;
}
void
runCV
(
Target
target
,
const
std
::
string
&
xmlPath
,
const
std
::
string
&
binPath
,
const
std
::
map
<
std
::
string
,
cv
::
Mat
>&
inputsMap
,
std
::
map
<
std
::
string
,
cv
::
Mat
>&
outputsMap
)
{
Net
net
=
readNet
(
xmlPath
,
binPath
);
for
(
auto
&
it
:
inputsMap
)
net
.
setInput
(
it
.
second
,
it
.
first
);
net
.
setPreferableTarget
(
target
);
std
::
vector
<
String
>
outNames
=
getOutputsNames
(
net
);
std
::
vector
<
Mat
>
outs
;
net
.
forward
(
outs
,
outNames
);
outputsMap
.
clear
();
EXPECT_EQ
(
outs
.
size
(),
outNames
.
size
());
for
(
int
i
=
0
;
i
<
outs
.
size
();
++
i
)
{
EXPECT_TRUE
(
outputsMap
.
insert
({
outNames
[
i
],
outs
[
i
]}).
second
);
}
}
typedef
TestWithParam
<
tuple
<
Target
,
String
>
>
DNNTestOpenVINO
;
TEST_P
(
DNNTestOpenVINO
,
models
)
{
Target
target
=
(
dnn
::
Target
)(
int
)
get
<
0
>
(
GetParam
());
std
::
string
modelName
=
get
<
1
>
(
GetParam
());
if
(
modelName
==
"semantic-segmentation-adas-0001"
&&
target
==
DNN_TARGET_OPENCL_FP16
)
throw
SkipTestException
(
""
);
std
::
string
precision
=
(
target
==
DNN_TARGET_OPENCL_FP16
||
target
==
DNN_TARGET_MYRIAD
)
?
"FP16"
:
"FP32"
;
std
::
string
prefix
=
utils
::
fs
::
join
(
"intel_models"
,
utils
::
fs
::
join
(
modelName
,
utils
::
fs
::
join
(
precision
,
modelName
)));
std
::
string
xmlPath
=
findDataFile
(
prefix
+
".xml"
);
std
::
string
binPath
=
findDataFile
(
prefix
+
".bin"
);
std
::
map
<
std
::
string
,
cv
::
Mat
>
inputsMap
;
std
::
map
<
std
::
string
,
cv
::
Mat
>
ieOutputsMap
,
cvOutputsMap
;
runIE
(
target
,
xmlPath
,
binPath
,
inputsMap
,
ieOutputsMap
);
runCV
(
target
,
xmlPath
,
binPath
,
inputsMap
,
cvOutputsMap
);
EXPECT_EQ
(
ieOutputsMap
.
size
(),
cvOutputsMap
.
size
());
for
(
auto
&
srcIt
:
ieOutputsMap
)
{
auto
dstIt
=
cvOutputsMap
.
find
(
srcIt
.
first
);
CV_Assert
(
dstIt
!=
cvOutputsMap
.
end
());
double
normInf
=
cvtest
::
norm
(
srcIt
.
second
,
dstIt
->
second
,
cv
::
NORM_INF
);
EXPECT_EQ
(
normInf
,
0
);
}
}
static
testing
::
internal
::
ParamGenerator
<
String
>
intelModels
()
{
initDLDTDataPath
();
std
::
vector
<
String
>
modelsNames
;
std
::
string
path
;
try
{
path
=
findDataDirectory
(
"intel_models"
,
false
);
}
catch
(...)
{
std
::
cerr
<<
"ERROR: Can't find OpenVINO models. Check INTEL_CVSDK_DIR environment variable (run setup.sh)"
<<
std
::
endl
;
return
ValuesIn
(
modelsNames
);
// empty list
}
cv
::
utils
::
fs
::
glob_relative
(
path
,
""
,
modelsNames
,
false
,
true
);
modelsNames
.
erase
(
std
::
remove_if
(
modelsNames
.
begin
(),
modelsNames
.
end
(),
[
&
](
const
String
&
dir
){
return
!
utils
::
fs
::
isDirectory
(
utils
::
fs
::
join
(
path
,
dir
));
}),
modelsNames
.
end
()
);
CV_Assert
(
!
modelsNames
.
empty
());
return
ValuesIn
(
modelsNames
);
}
INSTANTIATE_TEST_CASE_P
(
/**/
,
DNNTestOpenVINO
,
Combine
(
Values
(
DNN_TARGET_CPU
,
DNN_TARGET_OPENCL
,
DNN_TARGET_OPENCL_FP16
),
intelModels
()
));
}}
#endif // HAVE_INF_ENGINE
modules/ts/include/opencv2/ts.hpp
浏览文件 @
236f3839
...
...
@@ -103,6 +103,7 @@ using std::pair;
using
std
::
make_pair
;
using
testing
::
TestWithParam
;
using
testing
::
Values
;
using
testing
::
ValuesIn
;
using
testing
::
Combine
;
using
cv
::
Mat
;
...
...
@@ -654,6 +655,11 @@ void addDataSearchSubDirectory(const std::string& subdir);
*/
std
::
string
findDataFile
(
const
std
::
string
&
relative_path
,
bool
required
=
true
);
/*! @brief Try to find requested data directory
@sa findDataFile
*/
std
::
string
findDataDirectory
(
const
std
::
string
&
relative_path
,
bool
required
=
true
);
#ifndef __CV_TEST_EXEC_ARGS
#if defined(_MSC_VER) && (_MSC_VER <= 1400)
...
...
modules/ts/src/ts.cpp
浏览文件 @
236f3839
...
...
@@ -772,16 +772,24 @@ void addDataSearchSubDirectory(const std::string& subdir)
TS
::
ptr
()
->
data_search_subdir
.
push_back
(
subdir
);
}
st
d
::
string
findDataFile
(
const
std
::
string
&
relative_path
,
bool
required
)
st
atic
std
::
string
findData
(
const
std
::
string
&
relative_path
,
bool
required
,
bool
findDirectory
)
{
#define TEST_TRY_FILE_WITH_PREFIX(prefix) \
{ \
std::string path = path_join(prefix, relative_path); \
/*printf("Trying %s\n", path.c_str());*/
\
FILE* f = fopen(path.c_str(), "rb"); \
if(f) { \
fclose(f); \
return path; \
if (findDirectory) \
{ \
if (isDirectory(path)) \
return path; \
} \
else \
{ \
FILE* f = fopen(path.c_str(), "rb"); \
if(f) { \
fclose(f); \
return path; \
} \
} \
}
...
...
@@ -842,11 +850,21 @@ std::string findDataFile(const std::string& relative_path, bool required)
}
#endif
#endif
const
char
*
type
=
findDirectory
?
"directory"
:
"data file"
;
if
(
required
)
CV_Error
(
cv
::
Error
::
StsError
,
cv
::
format
(
"OpenCV tests: Can't find required data file: %s"
,
relative_path
.
c_str
()));
throw
SkipTestException
(
cv
::
format
(
"OpenCV tests: Can't find data file: %s"
,
relative_path
.
c_str
()));
CV_Error
(
cv
::
Error
::
StsError
,
cv
::
format
(
"OpenCV tests: Can't find required %s: %s"
,
type
,
relative_path
.
c_str
()));
throw
SkipTestException
(
cv
::
format
(
"OpenCV tests: Can't find %s: %s"
,
type
,
relative_path
.
c_str
()));
}
std
::
string
findDataFile
(
const
std
::
string
&
relative_path
,
bool
required
)
{
return
findData
(
relative_path
,
required
,
false
);
}
std
::
string
findDataDirectory
(
const
std
::
string
&
relative_path
,
bool
required
)
{
return
findData
(
relative_path
,
required
,
true
);
}
}
//namespace cvtest
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录