Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
cb0d6959
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,发现更多精彩内容 >>
提交
cb0d6959
编写于
9月 15, 2017
作者:
V
Vadim Pisarevsky
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #9616 from dkurt:feature_dnn_tf_importer_atrous_conv
上级
d60de63f
58b890b9
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
59 addition
and
16 deletion
+59
-16
modules/dnn/src/layers/convolution_layer.cpp
modules/dnn/src/layers/convolution_layer.cpp
+2
-2
modules/dnn/src/layers/layers_common.cpp
modules/dnn/src/layers/layers_common.cpp
+6
-6
modules/dnn/src/layers/layers_common.hpp
modules/dnn/src/layers/layers_common.hpp
+2
-2
modules/dnn/src/layers/pooling_layer.cpp
modules/dnn/src/layers/pooling_layer.cpp
+2
-3
modules/dnn/src/tensorflow/tf_importer.cpp
modules/dnn/src/tensorflow/tf_importer.cpp
+45
-3
modules/dnn/test/test_tf_importer.cpp
modules/dnn/test/test_tf_importer.cpp
+2
-0
未找到文件。
modules/dnn/src/layers/convolution_layer.cpp
浏览文件 @
cb0d6959
...
...
@@ -81,7 +81,7 @@ public:
Size
outSize
=
Size
(
outputs
[
0
].
size
[
3
],
outputs
[
0
].
size
[
2
]);
getConvPoolPaddings
(
Size
(
input
.
size
[
3
],
input
.
size
[
2
]),
outSize
,
kernel
,
stride
,
padMode
,
pad
);
kernel
,
stride
,
padMode
,
dilation
,
pad
);
}
bool
hasBias
()
const
...
...
@@ -183,7 +183,7 @@ public:
}
else
{
getConvPoolOutParams
(
Size
(
inpW
,
inpH
),
kernel
,
stride
,
padMode
,
out
);
getConvPoolOutParams
(
Size
(
inpW
,
inpH
),
kernel
,
stride
,
padMode
,
dilation
,
out
);
}
int
ngroups
=
inpCn
/
blobs
[
0
].
size
[
1
];
...
...
modules/dnn/src/layers/layers_common.cpp
浏览文件 @
cb0d6959
...
...
@@ -167,12 +167,12 @@ void getConvolutionKernelParams(const LayerParams ¶ms, int &kernelH, int &ke
// we pad more on the right and bottom than on the top and left.
void
getConvPoolOutParams
(
const
Size
&
inp
,
const
Size
&
kernel
,
const
Size
&
stride
,
const
String
&
padMode
,
Size
&
out
)
const
Size
&
dilation
,
Size
&
out
)
{
if
(
padMode
==
"VALID"
)
{
out
.
height
=
(
inp
.
height
-
kernel
.
height
+
stride
.
height
)
/
stride
.
height
;
out
.
width
=
(
inp
.
width
-
kernel
.
width
+
stride
.
width
)
/
stride
.
width
;
out
.
height
=
(
inp
.
height
-
(
dilation
.
height
*
(
kernel
.
height
-
1
)
+
1
)
+
stride
.
height
)
/
stride
.
height
;
out
.
width
=
(
inp
.
width
-
(
dilation
.
width
*
(
kernel
.
width
-
1
)
+
1
)
+
stride
.
width
)
/
stride
.
width
;
}
else
if
(
padMode
==
"SAME"
)
{
...
...
@@ -187,7 +187,7 @@ void getConvPoolOutParams(const Size& inp, const Size &kernel,
void
getConvPoolPaddings
(
const
Size
&
inp
,
const
Size
&
out
,
const
Size
&
kernel
,
const
Size
&
stride
,
const
String
&
padMode
,
Size
&
pad
)
const
String
&
padMode
,
const
Size
&
dilation
,
Size
&
pad
)
{
if
(
padMode
==
"VALID"
)
{
...
...
@@ -195,8 +195,8 @@ void getConvPoolPaddings(const Size& inp, const Size& out,
}
else
if
(
padMode
==
"SAME"
)
{
int
Ph
=
std
::
max
(
0
,
(
out
.
height
-
1
)
*
stride
.
height
+
kernel
.
height
-
inp
.
height
);
int
Pw
=
std
::
max
(
0
,
(
out
.
width
-
1
)
*
stride
.
width
+
kernel
.
width
-
inp
.
width
);
int
Ph
=
std
::
max
(
0
,
(
out
.
height
-
1
)
*
stride
.
height
+
(
dilation
.
height
*
(
kernel
.
height
-
1
)
+
1
)
-
inp
.
height
);
int
Pw
=
std
::
max
(
0
,
(
out
.
width
-
1
)
*
stride
.
width
+
(
dilation
.
width
*
(
kernel
.
width
-
1
)
+
1
)
-
inp
.
width
);
// For odd values of total padding, add more padding at the 'right'
// side of the given dimension.
pad
=
cv
::
Size
(
Pw
/
2
,
Ph
/
2
);
...
...
modules/dnn/src/layers/layers_common.hpp
浏览文件 @
cb0d6959
...
...
@@ -64,11 +64,11 @@ void getPoolingKernelParams(const LayerParams ¶ms, int &kernelH, int &kernel
void
getConvPoolOutParams
(
const
Size
&
inp
,
const
Size
&
kernel
,
const
Size
&
stride
,
const
String
&
padMode
,
Size
&
out
);
const
Size
&
dilation
,
Size
&
out
);
void
getConvPoolPaddings
(
const
Size
&
inp
,
const
Size
&
out
,
const
Size
&
kernel
,
const
Size
&
stride
,
const
String
&
padMode
,
Size
&
pad
);
const
String
&
padMode
,
const
Size
&
dilation
,
Size
&
pad
);
}
}
...
...
modules/dnn/src/layers/pooling_layer.cpp
浏览文件 @
cb0d6959
...
...
@@ -93,7 +93,7 @@ public:
kernel
=
inp
;
}
getConvPoolPaddings
(
inp
,
out
,
kernel
,
stride
,
padMode
,
pad
);
getConvPoolPaddings
(
inp
,
out
,
kernel
,
stride
,
padMode
,
Size
(
1
,
1
),
pad
);
}
virtual
bool
supportBackend
(
int
backendId
)
...
...
@@ -592,8 +592,7 @@ public:
}
else
{
getConvPoolOutParams
(
in
,
kernel
,
stride
,
padMode
,
out
);
getConvPoolOutParams
(
in
,
kernel
,
stride
,
padMode
,
Size
(
1
,
1
),
out
);
}
outputs
.
resize
(
type
==
MAX
?
2
*
inputs
.
size
()
:
inputs
.
size
());
...
...
modules/dnn/src/tensorflow/tf_importer.cpp
浏览文件 @
cb0d6959
...
...
@@ -88,6 +88,8 @@ static Mat getTensorContent(const tensorflow::TensorProto &tensor)
return
Mat
(
1
,
content
.
size
()
/
sizeof
(
float
),
CV_32FC1
,
(
void
*
)
content
.
c_str
()).
clone
();
case
tensorflow
::
DT_DOUBLE
:
return
Mat
(
1
,
content
.
size
()
/
sizeof
(
double
),
CV_64FC1
,
(
void
*
)
content
.
c_str
()).
clone
();
case
tensorflow
::
DT_INT32
:
return
Mat
(
1
,
content
.
size
()
/
sizeof
(
int32_t
),
CV_32SC1
,
(
void
*
)
content
.
c_str
()).
clone
();
case
tensorflow
::
DT_HALF
:
{
Mat
halfs
;
...
...
@@ -563,7 +565,7 @@ void TFImporter::populateNet(Net dstNet)
for
(
int
li
=
0
;
li
<
layersSize
;
li
++
)
{
const
tensorflow
::
NodeDef
&
layer
=
net
.
node
(
li
);
tensorflow
::
NodeDef
layer
=
net
.
node
(
li
);
String
name
=
layer
.
name
();
String
type
=
layer
.
op
();
LayerParams
layerParams
;
...
...
@@ -571,8 +573,38 @@ void TFImporter::populateNet(Net dstNet)
if
(
layers_to_ignore
.
find
(
li
)
!=
layers_to_ignore
.
end
())
continue
;
if
(
type
==
"Conv2D"
)
if
(
type
==
"Conv2D"
||
type
==
"SpaceToBatchND"
)
{
// The first node of dilated convolution subgraph.
// Extract input node, dilation rate and paddings.
std
::
string
input
=
layer
.
input
(
0
);
if
(
type
==
"SpaceToBatchND"
)
{
// op: "SpaceToBatchND"
// input: "input"
// input: "SpaceToBatchND/block_shape"
// input: "SpaceToBatchND/paddings"
CV_Assert
(
layer
.
input_size
()
==
3
);
DictValue
dilation
=
parseDims
(
getConstBlob
(
layer
,
value_id
,
1
));
CV_Assert
(
dilation
.
size
()
==
2
&&
dilation
.
get
<
int
>
(
0
)
==
dilation
.
get
<
int
>
(
1
));
layerParams
.
set
(
"dilation"
,
dilation
.
get
<
int
>
(
0
));
Mat
paddings
;
parseTensor
<
int
>
(
getConstBlob
(
layer
,
value_id
,
2
),
paddings
);
// paddings is a 2x2 matrix: [[top, bot], [left, right]]
layerParams
.
set
(
"pad_h"
,
paddings
.
at
<
float
>
(
0
));
layerParams
.
set
(
"pad_w"
,
paddings
.
at
<
float
>
(
2
));
StrIntVector
next_layers
=
getNextLayers
(
net
,
name
,
"Conv2D"
);
CV_Assert
(
next_layers
.
size
()
==
1
);
layer
=
net
.
node
(
next_layers
[
0
].
second
);
layers_to_ignore
[
next_layers
[
0
].
second
]
=
next_layers
[
0
].
first
;
name
=
layer
.
name
();
type
=
layer
.
op
();
}
layerParams
.
set
(
"bias_term"
,
false
);
layerParams
.
blobs
.
resize
(
1
);
...
...
@@ -597,11 +629,21 @@ void TFImporter::populateNet(Net dstNet)
setStrides
(
layerParams
,
layer
);
setPadding
(
layerParams
,
layer
);
// The final node of dilated convolution subgraph.
next_layers
=
getNextLayers
(
net
,
name
,
"BatchToSpaceND"
);
if
(
!
next_layers
.
empty
())
{
layerParams
.
set
(
"pad_mode"
,
""
);
// We use padding values.
CV_Assert
(
next_layers
.
size
()
==
1
);
ExcludeLayer
(
net
,
next_layers
[
0
].
second
,
0
,
false
);
layers_to_ignore
[
next_layers
[
0
].
second
]
=
next_layers
[
0
].
first
;
}
int
id
=
dstNet
.
addLayer
(
name
,
"Convolution"
,
layerParams
);
layer_id
[
name
]
=
id
;
// one input only
connect
(
layer_id
,
dstNet
,
parsePin
(
layer
.
input
(
0
)
),
id
,
0
);
connect
(
layer_id
,
dstNet
,
parsePin
(
input
),
id
,
0
);
}
else
if
(
type
==
"BiasAdd"
||
type
==
"Add"
)
{
...
...
modules/dnn/test/test_tf_importer.cpp
浏览文件 @
cb0d6959
...
...
@@ -96,6 +96,8 @@ static void runTensorFlowNet(const std::string& prefix,
TEST
(
Test_TensorFlow
,
single_conv
)
{
runTensorFlowNet
(
"single_conv"
);
runTensorFlowNet
(
"atrous_conv2d_valid"
);
runTensorFlowNet
(
"atrous_conv2d_same"
);
}
TEST
(
Test_TensorFlow
,
padding
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录