Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
fbde0c6c
O
Opencv
项目概览
Greenplum
/
Opencv
10 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
fbde0c6c
编写于
7月 14, 2021
作者:
A
Alexander Alekhin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
dnn(ie): fix handling of 1D and non-32F outputs of InferenceEngine
上级
602e7c83
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
120 addition
and
16 deletion
+120
-16
modules/dnn/src/dnn.cpp
modules/dnn/src/dnn.cpp
+21
-8
modules/dnn/src/ie_ngraph.cpp
modules/dnn/src/ie_ngraph.cpp
+90
-7
modules/dnn/src/ie_ngraph.hpp
modules/dnn/src/ie_ngraph.hpp
+9
-1
未找到文件。
modules/dnn/src/dnn.cpp
浏览文件 @
fbde0c6c
...
...
@@ -1944,7 +1944,10 @@ struct Net::Impl : public detail::NetImplBase
Ptr
<
InfEngineNgraphNode
>
ieNode
=
node
.
dynamicCast
<
InfEngineNgraphNode
>
();
CV_Assert
(
!
ieNode
.
empty
());
ieNode
->
net
->
reset
();
CV_Assert
(
ieNode
->
net
);
InfEngineNgraphNet
&
ienet
=
*
ieNode
->
net
;
ienet
.
reset
();
for
(
it
=
layers
.
begin
();
it
!=
layers
.
end
();
++
it
)
{
...
...
@@ -1961,16 +1964,26 @@ struct Net::Impl : public detail::NetImplBase
{
for
(
int
i
=
0
;
i
<
ld
.
outputBlobsWrappers
.
size
();
++
i
)
{
InferenceEngine
::
DataPtr
dataPtr
=
ngraphDataNode
(
ld
.
outputBlobsWrappers
[
i
]);
dataPtr
->
setName
(
ld
.
name
);
auto
it
=
ienet
.
outputsDesc
.
find
(
ld
.
name
);
if
(
it
!=
ienet
.
outputsDesc
.
end
())
{
const
InferenceEngine
::
TensorDesc
&
descriptor
=
it
->
second
;
InferenceEngine
::
DataPtr
dataPtr
=
ngraphDataOutputNode
(
ld
.
outputBlobsWrappers
[
i
],
descriptor
,
ld
.
name
);
dataPtr
->
setName
(
ld
.
name
);
}
else
{
InferenceEngine
::
DataPtr
dataPtr
=
ngraphDataNode
(
ld
.
outputBlobsWrappers
[
i
]);
dataPtr
->
setName
(
ld
.
name
);
}
}
}
ie
Node
->
net
->
addBlobs
(
ld
.
inputBlobsWrappers
);
ie
Node
->
net
->
addBlobs
(
ld
.
outputBlobsWrappers
);
ie
net
.
addBlobs
(
ld
.
inputBlobsWrappers
);
ie
net
.
addBlobs
(
ld
.
outputBlobsWrappers
);
ld
.
skip
=
true
;
}
layers
[
lastLayerId
].
skip
=
false
;
ie
Node
->
net
->
init
((
Target
)
preferableTarget
);
ie
net
.
init
((
Target
)
preferableTarget
);
return
;
}
...
...
@@ -3719,8 +3732,8 @@ void Net::forward(OutputArrayOfArrays outputBlobs,
matvec
.
push_back
(
impl
->
getBlob
(
pins
[
i
]));
}
std
::
vector
<
Mat
>
&
outputvec
=
*
(
std
::
vector
<
Mat
>
*
)
outputBlobs
.
getObj
();
output
vec
=
matvec
;
outputBlobs
.
create
((
int
)
matvec
.
size
(),
1
,
CV_32F
/*FIXIT*/
,
-
1
);
// allocate vector
output
Blobs
.
assign
(
matvec
)
;
}
void
Net
::
forward
(
std
::
vector
<
std
::
vector
<
Mat
>
>&
outputBlobs
,
...
...
modules/dnn/src/ie_ngraph.cpp
浏览文件 @
fbde0c6c
...
...
@@ -789,21 +789,32 @@ void NgraphBackendLayer::forward(InputArrayOfArrays inputs, OutputArrayOfArrays
}
static
InferenceEngine
::
Layout
estimateLayout
(
const
Mat
&
m
)
static
InferenceEngine
::
Layout
estimateLayout
(
int
dims
)
{
if
(
m
.
dims
==
4
)
if
(
dims
==
4
)
return
InferenceEngine
::
Layout
::
NCHW
;
else
if
(
m
.
dims
==
3
)
else
if
(
dims
==
3
)
return
InferenceEngine
::
Layout
::
CHW
;
else
if
(
m
.
dims
==
2
)
else
if
(
dims
==
2
)
return
InferenceEngine
::
Layout
::
NC
;
else
if
(
m
.
dims
==
1
)
else
if
(
dims
==
1
)
return
InferenceEngine
::
Layout
::
C
;
else
if
(
m
.
dims
==
5
)
else
if
(
dims
==
5
)
return
InferenceEngine
::
Layout
::
NCDHW
;
else
return
InferenceEngine
::
Layout
::
ANY
;
}
static
inline
InferenceEngine
::
Layout
estimateLayout
(
size_t
dims
)
{
return
estimateLayout
((
int
)
dims
);
}
static
inline
InferenceEngine
::
Layout
estimateLayout
(
const
Mat
&
m
)
{
return
estimateLayout
(
m
.
dims
);
}
static
InferenceEngine
::
DataPtr
wrapToInfEngineDataNode
(
const
Mat
&
m
,
const
std
::
string
&
name
=
""
)
{
...
...
@@ -839,6 +850,7 @@ InferenceEngine::Blob::Ptr wrapToNgraphBlob(const Mat& m, InferenceEngine::Layou
NgraphBackendWrapper
::
NgraphBackendWrapper
(
int
targetId
,
const
cv
::
Mat
&
m
)
:
BackendWrapper
(
DNN_BACKEND_INFERENCE_ENGINE_NGRAPH
,
targetId
)
,
host
((
Mat
*
)
&
m
)
{
dataPtr
=
wrapToInfEngineDataNode
(
m
);
blob
=
wrapToNgraphBlob
(
m
,
estimateLayout
(
m
));
...
...
@@ -890,7 +902,11 @@ InferenceEngine::Blob::Ptr copyBlob(const InferenceEngine::Blob::Ptr& blob)
copy
=
InferenceEngine
::
make_shared_blob
<
uint8_t
>
(
description
);
}
else
CV_Error
(
Error
::
StsNotImplemented
,
"Unsupported blob precision"
);
{
std
::
ostringstream
msg
;
msg
<<
precision
;
CV_Error_
(
Error
::
StsNotImplemented
,
(
"Unsupported blob precision: %s"
,
msg
.
str
().
c_str
()));
}
copy
->
allocate
();
return
copy
;
}
...
...
@@ -903,6 +919,66 @@ InferenceEngine::DataPtr ngraphDataNode(const Ptr<BackendWrapper>& ptr)
return
p
->
dataPtr
;
}
static
InferenceEngine
::
Blob
::
Ptr
reallocateBlob
(
Mat
&
m
,
const
InferenceEngine
::
TensorDesc
&
description
)
{
auto
dims
=
description
.
getDims
();
auto
layout
=
estimateLayout
(
dims
.
size
());
MatShape
matShape
(
dims
.
begin
(),
dims
.
end
());
if
(
description
.
getPrecision
()
==
InferenceEngine
::
Precision
::
FP32
)
{
m
.
create
(
matShape
,
CV_32FC1
);
return
InferenceEngine
::
make_shared_blob
<
float
>
(
{
description
.
getPrecision
(),
dims
,
layout
},
(
float
*
)
m
.
data
);
}
else
if
(
description
.
getPrecision
()
==
InferenceEngine
::
Precision
::
I32
)
{
m
.
create
(
matShape
,
CV_32SC1
);
return
InferenceEngine
::
make_shared_blob
<
int
>
(
{
description
.
getPrecision
(),
dims
,
layout
},
(
int
*
)
m
.
data
);
}
else
if
(
description
.
getPrecision
()
==
InferenceEngine
::
Precision
::
U8
)
{
m
.
create
(
matShape
,
CV_8UC1
);
return
InferenceEngine
::
make_shared_blob
<
uchar
>
(
{
description
.
getPrecision
(),
dims
,
layout
},
(
uchar
*
)
m
.
data
);
}
std
::
ostringstream
msg
;
msg
<<
"Unsupported IE precision: "
<<
description
.
getPrecision
();
CV_Error
(
Error
::
StsNotImplemented
,
msg
.
str
());
}
InferenceEngine
::
DataPtr
ngraphDataOutputNode
(
const
Ptr
<
BackendWrapper
>&
ptr
,
const
InferenceEngine
::
TensorDesc
&
description
,
const
std
::
string
name
)
{
CV_Assert
(
!
ptr
.
empty
());
Ptr
<
NgraphBackendWrapper
>
p
=
ptr
.
dynamicCast
<
NgraphBackendWrapper
>
();
CV_Assert
(
!
p
.
empty
());
NgraphBackendWrapper
&
w
=
*
p
;
const
InferenceEngine
::
TensorDesc
&
blobDesc
=
w
.
blob
.
get
()
->
getTensorDesc
();
auto
dims
=
description
.
getDims
();
bool
reallocate
=
false
;
if
(
blobDesc
.
getPrecision
()
!=
description
.
getPrecision
())
{
reallocate
=
true
;
CV_LOG_WARNING
(
NULL
,
"Reallocate output '"
<<
name
<<
"' blob due to wrong precision: "
<<
blobDesc
.
getPrecision
()
<<
" => "
<<
description
.
getPrecision
()
<<
" ndims="
<<
dims
.
size
());
}
if
(
dims
.
size
()
!=
blobDesc
.
getDims
().
size
())
{
reallocate
=
true
;
CV_LOG_WARNING
(
NULL
,
"Reallocate output '"
<<
name
<<
"' blob due to wrong dims: "
<<
blobDesc
.
getDims
().
size
()
<<
" => "
<<
dims
.
size
());
}
if
(
reallocate
)
{
auto
layout
=
estimateLayout
(
dims
.
size
());
w
.
dataPtr
=
InferenceEngine
::
DataPtr
(
new
InferenceEngine
::
Data
(
name
,
{
description
.
getPrecision
(),
dims
,
layout
}));
w
.
blob
=
reallocateBlob
(
*
w
.
host
,
description
);
}
return
w
.
dataPtr
;
}
void
forwardNgraph
(
const
std
::
vector
<
Ptr
<
BackendWrapper
>
>&
outBlobsWrappers
,
Ptr
<
BackendNode
>&
node
,
bool
isAsync
)
...
...
@@ -918,6 +994,13 @@ void InfEngineNgraphNet::reset()
allBlobs
.
clear
();
infRequests
.
clear
();
isInit
=
false
;
outputsDesc
.
clear
();
for
(
const
auto
&
it
:
cnn
.
getOutputsInfo
())
{
const
std
::
string
&
name
=
it
.
first
;
outputsDesc
.
insert
({
name
,
it
.
second
->
getTensorDesc
()});
}
}
void
InfEngineNgraphNet
::
addBlobs
(
const
std
::
vector
<
cv
::
Ptr
<
BackendWrapper
>
>&
ptrs
)
...
...
modules/dnn/src/ie_ngraph.hpp
浏览文件 @
fbde0c6c
...
...
@@ -54,7 +54,8 @@ public:
void
setNodePtr
(
std
::
shared_ptr
<
ngraph
::
Node
>*
ptr
);
void
reset
();
private:
//private:
detail
::
NetImplBase
&
netImpl_
;
void
release
();
...
...
@@ -89,6 +90,8 @@ private:
bool
hasNetOwner
;
std
::
vector
<
std
::
string
>
requestedOutputs
;
std
::
unordered_set
<
std
::
shared_ptr
<
ngraph
::
Node
>>
unconnectedNodes
;
std
::
map
<
std
::
string
,
InferenceEngine
::
TensorDesc
>
outputsDesc
;
};
class
InfEngineNgraphNode
:
public
BackendNode
...
...
@@ -121,12 +124,17 @@ public:
virtual
void
copyToHost
()
CV_OVERRIDE
;
virtual
void
setHostDirty
()
CV_OVERRIDE
;
Mat
*
host
;
InferenceEngine
::
DataPtr
dataPtr
;
InferenceEngine
::
Blob
::
Ptr
blob
;
AsyncArray
futureMat
;
};
InferenceEngine
::
DataPtr
ngraphDataNode
(
const
Ptr
<
BackendWrapper
>&
ptr
);
InferenceEngine
::
DataPtr
ngraphDataOutputNode
(
const
Ptr
<
BackendWrapper
>&
ptr
,
const
InferenceEngine
::
TensorDesc
&
description
,
const
std
::
string
name
);
// This is a fake class to run networks from Model Optimizer. Objects of that
// class simulate responses of layers are imported by OpenCV and supported by
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录