Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleDetection
提交
5229df52
P
PaddleDetection
项目概览
PaddlePaddle
/
PaddleDetection
大约 1 年 前同步成功
通知
695
Star
11112
Fork
2696
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
184
列表
看板
标记
里程碑
合并请求
40
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleDetection
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
184
Issue
184
列表
看板
标记
里程碑
合并请求
40
合并请求
40
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5229df52
编写于
8月 02, 2017
作者:
X
xzl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
ignore im2col if not necessary in conv 1 * 1
上级
f70e8077
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
94 addition
and
51 deletion
+94
-51
paddle/function/ConvOp.h
paddle/function/ConvOp.h
+7
-0
paddle/function/GemmConvOp.cpp
paddle/function/GemmConvOp.cpp
+87
-51
未找到文件。
paddle/function/ConvOp.h
浏览文件 @
5229df52
...
...
@@ -109,6 +109,13 @@ protected:
return
filter
[
filter
.
ndims
()
-
1
];
}
// determine whether im2col needs to be performed
inline
bool
isSkipIm2col
(
const
TensorShape
&
filter
)
const
{
return
(
getFilterHeight
(
filter
)
==
1
&&
getFilterWidth
(
filter
)
==
1
&&
strideH
()
==
1
&&
strideW
()
==
1
&&
paddingH
()
==
0
&&
paddingW
()
==
0
);
}
std
::
vector
<
size_t
>
strides_
;
std
::
vector
<
size_t
>
paddings_
;
...
...
paddle/function/GemmConvOp.cpp
浏览文件 @
5229df52
...
...
@@ -66,16 +66,23 @@ public:
real
*
inputData
=
inputs
[
0
].
data
<
real
>
();
real
*
filterData
=
inputs
[
1
].
data
<
real
>
();
real
*
outputData
=
outputs
[
0
].
data
<
real
>
();
bool
skipIm2col
=
isSkipIm2col
(
filter
);
TensorShape
imShape
=
TensorShape
({
inputChannels
/
groups_
,
inputHeight
,
inputWidth
});
TensorShape
colShape
=
TensorShape
({
inputChannels
/
groups_
,
filterHeight
,
filterWidth
,
outputHeight
,
outputWidth
});
resizeBuffer
<
Device
>
(
colShape
.
getElements
());
real
*
colData
=
reinterpret_cast
<
real
*>
(
memory_
->
getBuf
());
TensorShape
colShape
;
real
*
colBuffer
,
*
colData
=
NULL
;
if
(
!
skipIm2col
)
{
colShape
=
TensorShape
({
inputChannels
/
groups_
,
filterHeight
,
filterWidth
,
outputHeight
,
outputWidth
});
resizeBuffer
<
Device
>
(
colShape
.
getElements
());
colData
=
reinterpret_cast
<
real
*>
(
memory_
->
getBuf
());
}
Im2ColFunctor
<
kCFO
,
Device
,
real
>
im2col
;
GemmFunctor
<
Device
,
real
>
gemm
;
...
...
@@ -86,15 +93,18 @@ public:
for
(
size_t
i
=
0
;
i
<
batchSize
;
i
++
)
{
for
(
size_t
g
=
0
;
g
<
groups_
;
g
++
)
{
im2col
(
inputData
+
g
*
inputOffset
,
imShape
,
colData
,
colShape
,
strideH
(),
strideW
(),
paddingH
(),
paddingW
());
colBuffer
=
inputData
+
g
*
inputOffset
;
if
(
!
skipIm2col
)
{
im2col
(
inputData
+
g
*
inputOffset
,
imShape
,
colData
,
colShape
,
strideH
(),
strideW
(),
paddingH
(),
paddingW
());
colBuffer
=
colData
;
}
int
M
=
outputChannels
/
groups_
;
int
N
=
outputHeight
*
outputWidth
;
int
K
=
inputChannels
/
groups_
*
filterHeight
*
filterWidth
;
...
...
@@ -106,7 +116,7 @@ public:
1.0
f
,
filterData
+
g
*
filterOffset
,
K
,
col
Data
,
col
Buffer
,
N
,
beta
,
outputData
+
g
*
outputOffset
,
...
...
@@ -159,19 +169,27 @@ public:
real
*
outputGrad
=
inputs
[
0
].
data
<
real
>
();
real
*
filterData
=
inputs
[
1
].
data
<
real
>
();
real
*
inputGrad
=
outputs
[
0
].
data
<
real
>
();
bool
skipIm2col
=
isSkipIm2col
(
filter
);
TensorShape
imShape
=
TensorShape
({
inputChannels
/
groups_
,
inputHeight
,
inputWidth
});
TensorShape
colShape
=
TensorShape
({
inputChannels
/
groups_
,
filterHeight
,
filterWidth
,
outputHeight
,
outputWidth
});
resizeBuffer
<
Device
>
(
colShape
.
getElements
());
real
*
colData
=
reinterpret_cast
<
real
*>
(
memory_
->
getBuf
());
TensorShape
colShape
;
real
*
colBuffer
,
*
colData
=
NULL
;
if
(
!
skipIm2col
)
{
colShape
=
TensorShape
({
inputChannels
/
groups_
,
filterHeight
,
filterWidth
,
outputHeight
,
outputWidth
});
resizeBuffer
<
Device
>
(
colShape
.
getElements
());
colData
=
reinterpret_cast
<
real
*>
(
memory_
->
getBuf
());
}
Col2ImFunctor
<
kCFO
,
Device
,
real
>
col2im
;
GemmFunctor
<
Device
,
real
>
gemm
;
size_t
inputOffset
=
imShape
.
getElements
();
size_t
outputOffset
=
(
outputChannels
/
groups_
)
*
outputHeight
*
outputWidth
;
...
...
@@ -182,6 +200,12 @@ public:
int
K
=
outputChannels
/
groups_
;
int
N
=
outputHeight
*
outputWidth
;
int
M
=
inputChannels
/
groups_
*
filterHeight
*
filterWidth
;
colBuffer
=
colData
;
real
scale
=
0.0
f
;
if
(
skipIm2col
)
{
colBuffer
=
inputGrad
+
g
*
inputOffset
;
scale
=
1.0
f
;
}
gemm
(
CblasTrans
,
CblasNoTrans
,
M
,
...
...
@@ -192,17 +216,19 @@ public:
M
,
outputGrad
+
g
*
outputOffset
,
N
,
0.0
f
,
col
Data
,
scale
,
col
Buffer
,
N
);
col2im
(
inputGrad
+
g
*
inputOffset
,
imShape
,
colData
,
colShape
,
strideH
(),
strideW
(),
paddingH
(),
paddingW
());
if
(
!
skipIm2col
)
{
col2im
(
inputGrad
+
g
*
inputOffset
,
imShape
,
colBuffer
,
colShape
,
strideH
(),
strideW
(),
paddingH
(),
paddingW
());
}
}
inputGrad
+=
inputChannels
*
inputHeight
*
inputWidth
;
outputGrad
+=
outputChannels
*
outputHeight
*
outputWidth
;
...
...
@@ -255,16 +281,23 @@ public:
real
*
outputGrad
=
inputs
[
0
].
data
<
real
>
();
real
*
inputData
=
inputs
[
1
].
data
<
real
>
();
real
*
filterGrad
=
outputs
[
0
].
data
<
real
>
();
bool
skipIm2col
=
isSkipIm2col
(
filter
);
TensorShape
imShape
=
TensorShape
({
inputChannels
/
groups_
,
inputHeight
,
inputWidth
});
TensorShape
colShape
=
TensorShape
({
inputChannels
/
groups_
,
filterHeight
,
filterWidth
,
outputHeight
,
outputWidth
});
resizeBuffer
<
Device
>
(
colShape
.
getElements
());
real
*
colData
=
reinterpret_cast
<
real
*>
(
memory_
->
getBuf
());
TensorShape
colShape
;
real
*
colBuffer
,
*
colData
=
NULL
;
if
(
!
skipIm2col
)
{
colShape
=
TensorShape
({
inputChannels
/
groups_
,
filterHeight
,
filterWidth
,
outputHeight
,
outputWidth
});
resizeBuffer
<
Device
>
(
colShape
.
getElements
());
colData
=
reinterpret_cast
<
real
*>
(
memory_
->
getBuf
());
}
Im2ColFunctor
<
kCFO
,
Device
,
real
>
im2col
;
GemmFunctor
<
Device
,
real
>
gemm
;
...
...
@@ -274,15 +307,18 @@ public:
size_t
filterOffset
=
filter
.
getElements
()
/
groups_
;
for
(
size_t
i
=
0
;
i
<
batchSize
;
i
++
)
{
for
(
size_t
g
=
0
;
g
<
groups_
;
g
++
)
{
im2col
(
inputData
+
g
*
inputOffset
,
imShape
,
colData
,
colShape
,
strideH
(),
strideW
(),
paddingH
(),
paddingW
());
colBuffer
=
inputData
+
g
*
inputOffset
;
if
(
!
skipIm2col
)
{
im2col
(
inputData
+
g
*
inputOffset
,
imShape
,
colData
,
colShape
,
strideH
(),
strideW
(),
paddingH
(),
paddingW
());
colBuffer
=
colData
;
}
int
M
=
outputChannels
/
groups_
;
int
K
=
outputHeight
*
outputWidth
;
int
N
=
inputChannels
/
groups_
*
filterHeight
*
filterWidth
;
...
...
@@ -294,7 +330,7 @@ public:
1.0
f
,
outputGrad
+
g
*
outputOffset
,
K
,
col
Data
,
col
Buffer
,
K
,
i
==
0
?
beta
:
1.0
f
,
filterGrad
+
g
*
filterOffset
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录