Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
198164ad
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
198164ad
编写于
7月 10, 2017
作者:
X
xzl
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use the expandconvlayer forward and backward, add the explain for class
上级
064dc888
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
9 addition
and
140 deletion
+9
-140
paddle/function/DepthwiseConvOp.cpp
paddle/function/DepthwiseConvOp.cpp
+0
-3
paddle/function/DepthwiseConvOp.h
paddle/function/DepthwiseConvOp.h
+1
-3
paddle/function/DepthwiseConvOpGpu.cu
paddle/function/DepthwiseConvOpGpu.cu
+5
-17
paddle/gserver/layers/DepthwiseConvLayer.cpp
paddle/gserver/layers/DepthwiseConvLayer.cpp
+0
-104
paddle/gserver/layers/DepthwiseConvLayer.h
paddle/gserver/layers/DepthwiseConvLayer.h
+3
-13
未找到文件。
paddle/function/DepthwiseConvOp.cpp
浏览文件 @
198164ad
...
...
@@ -81,7 +81,6 @@ public:
int
paddingH
,
int
paddingW
,
T
*
colData
,
T
*
multiplierData
,
T
*
filterGrad
)
{}
};
...
...
@@ -247,7 +246,6 @@ public:
real
*
outputGrad
=
inputs
[
0
].
data
<
real
>
();
real
*
inputData
=
inputs
[
1
].
data
<
real
>
();
real
*
multiplierData
=
inputs
[
2
].
data
<
real
>
();
real
*
filterGrad
=
outputs
[
0
].
data
<
real
>
();
int
size
=
...
...
@@ -273,7 +271,6 @@ public:
paddingH
(),
paddingW
(),
colData
,
multiplierData
,
filterGrad
);
}
};
...
...
paddle/function/DepthwiseConvOp.h
浏览文件 @
198164ad
...
...
@@ -148,9 +148,7 @@ public:
int
paddingH
,
int
paddingW
,
T
*
colData
,
T
*
multiplierData
,
T
*
filterGrad
);
};
// namespace paddle
};
}
// namespace paddle
paddle/function/DepthwiseConvOpGpu.cu
浏览文件 @
198164ad
...
...
@@ -14,6 +14,7 @@ limitations under the License. */
#include "DepthwiseConvOp.h"
#include "GemmFunctor.h"
#include "paddle/math/BaseMatrix.h"
namespace
paddle
{
// CUDA kernel to compute the depthwise convolution forward pass
...
...
@@ -266,7 +267,6 @@ public:
int
paddingH
,
int
paddingW
,
T
*
colData
,
T
*
multiplierData
,
T
*
filterGrad
){
int
colDataSize
=
inputChannels
*
filterHeight
*
filterWidth
*
outputHeight
*
outputWidth
;
...
...
@@ -276,6 +276,7 @@ public:
size_t
blockY
=
(
blocks
+
512
-
1
)
/
512
;
dim3
threads
(
1024
,
1
);
dim3
grid
(
blockX
,
blockY
);
BaseMatrix
filterGradMatrix
(
inputChannels
*
filterHeight
*
filterWidth
,
1
,
filterGrad
,
false
,
true
);
for
(
int
i
=
0
;
i
<
batchSize
;
i
++
)
{
ConvolutionDepthwiseFilterBackward
<
T
>
...
...
@@ -298,25 +299,12 @@ public:
paddingW
,
colData
);
GemmFunctor
<
DEVICE_TYPE_GPU
,
real
>
gemm
;
int
M
=
colDataSize
/
outputHeight
/
outputWidth
;
int
N
=
1
;
int
K
=
outputHeight
*
outputWidth
;
gemm
(
CblasNoTrans
,
CblasNoTrans
,
M
,
N
,
K
,
(
T
)
1.0
,
colData
,
K
,
multiplierData
,
N
,
(
T
)
1.0
,
filterGrad
,
N
);
BaseMatrix
colMatrix
(
M
,
K
,
colData
,
false
,
true
);
filterGradMatrix
.
sumRows
(
colMatrix
,
(
T
)
1.0
,
(
T
)
1.0
);
}
//gemv
}
};
...
...
paddle/gserver/layers/DepthwiseConvLayer.cpp
浏览文件 @
198164ad
...
...
@@ -29,18 +29,10 @@ bool DepthwiseConvLayer::init(const LayerMap &layerMap,
inputShape_
.
resize
(
numInputs
);
filterShape_
.
resize
(
numInputs
);
outputShape_
.
resize
(
numInputs
);
multiplierShape_
.
resize
(
numInputs
);
weightMultiplier_
.
resize
(
numInputs
);
for
(
int
i
=
0
;
i
<
config_
.
inputs_size
();
i
++
)
{
std
::
vector
<
size_t
>
paddings
=
{(
size_t
)
paddingY_
[
i
],
(
size_t
)
padding_
[
i
]};
std
::
vector
<
size_t
>
strides
=
{(
size_t
)
strideY_
[
i
],
(
size_t
)
stride_
[
i
]};
Matrix
::
resizeOrCreate
(
weightMultiplier_
[
i
],
(
size_t
)
outputH_
[
i
]
*
(
size_t
)
outputW_
[
i
],
(
size_t
)
1
,
false
,
useGpu_
);
weightMultiplier_
[
i
]
->
one
();
createFunction
(
forward_
,
"DepthwiseConv"
,
FuncConfig
()
...
...
@@ -65,100 +57,4 @@ bool DepthwiseConvLayer::init(const LayerMap &layerMap,
return
true
;
}
// i is the index of input layers
#define BACKWARD_INPUT(i, inputs, outputs) \
backward_[2 * i]->calc(inputs, outputs)
#define BACKWARD_FILTER(i, inputs, outputs) \
backward_[2 * i + 1]->calc(inputs, outputs)
// compute the depthwise convolution forward pass
void
DepthwiseConvLayer
::
forward
(
PassType
passType
)
{
Layer
::
forward
(
passType
);
size_t
batchSize
=
inputLayers_
[
0
]
->
getOutputValue
()
->
getHeight
();
resetOutput
(
batchSize
,
getOutputSize
());
// Calculate the shape of the input, output, and filter.
for
(
size_t
i
=
0
;
i
<
inputLayers_
.
size
();
++
i
)
{
inputShape_
[
i
]
=
TensorShape
({(
size_t
)
batchSize
,
(
size_t
)
channels_
[
i
],
(
size_t
)
imgSizeH_
[
i
],
(
size_t
)
imgSizeW_
[
i
]});
multiplierShape_
[
i
]
=
TensorShape
({(
size_t
)
outputH_
[
i
]
*
(
size_t
)
outputW_
[
i
],
(
size_t
)
1
});
filterShape_
[
i
]
=
TensorShape
({(
size_t
)
groups_
[
i
],
(
size_t
)
numFilters_
/
groups_
[
i
],
(
size_t
)
channels_
[
i
]
/
groups_
[
i
],
(
size_t
)
filterSizeY_
[
i
],
(
size_t
)
filterSize_
[
i
]});
outputShape_
[
i
]
=
TensorShape
({(
size_t
)
batchSize
,
(
size_t
)
numFilters_
,
(
size_t
)
outputH_
[
i
],
(
size_t
)
outputW_
[
i
]});
}
// Calculate the output value.
for
(
size_t
i
=
0
;
i
<
inputLayers_
.
size
();
++
i
)
{
BufferArgs
inputs
;
BufferArgs
outputs
;
inputs
.
addArg
(
*
getInputValue
(
i
),
inputShape_
[
i
]);
inputs
.
addArg
(
*
weights_
[
i
]
->
getW
(),
filterShape_
[
i
]);
outputs
.
addArg
(
*
getOutputValue
(),
outputShape_
[
i
],
i
==
0
?
ASSIGN_TO
:
ADD_TO
);
forward_
[
i
]
->
calc
(
inputs
,
outputs
);
}
/* add the bias-vector */
if
(
biases_
.
get
())
{
if
(
sharedBiases_
)
{
addSharedBias
();
}
else
{
addUnsharedBias
();
}
}
/* activation */
forwardActivation
();
}
// compute the depthwise convolution backprop.
void
DepthwiseConvLayer
::
backward
(
const
UpdateCallback
&
callback
)
{
backwardActivation
();
MatrixPtr
outGrad
=
getOutputGrad
();
if
(
biases_
&&
biases_
->
getWGrad
())
{
bpropBiases
(
outGrad
);
/* Increasing the number of gradient */
biases_
->
getParameterPtr
()
->
incUpdate
(
callback
);
}
// Calculate the input grad and filter grad.
for
(
size_t
i
=
0
;
i
<
inputLayers_
.
size
();
++
i
)
{
if
(
getInputGrad
(
i
))
{
BufferArgs
inputs
;
BufferArgs
outputs
;
inputs
.
addArg
(
*
getOutputGrad
(),
outputShape_
[
i
]);
inputs
.
addArg
(
*
weights_
[
i
]
->
getW
(),
filterShape_
[
i
]);
outputs
.
addArg
(
*
getInputGrad
(
i
),
inputShape_
[
i
],
ADD_TO
);
BACKWARD_INPUT
(
i
,
inputs
,
outputs
);
}
if
(
weights_
[
i
]
->
getWGrad
())
{
BufferArgs
inputs
;
BufferArgs
outputs
;
inputs
.
addArg
(
*
getOutputGrad
(),
outputShape_
[
i
]);
inputs
.
addArg
(
*
getInputValue
(
i
),
inputShape_
[
i
]);
inputs
.
addArg
(
*
weightMultiplier_
[
i
],
multiplierShape_
[
i
]);
// weight_multiplier
outputs
.
addArg
(
*
weights_
[
i
]
->
getWGrad
(),
filterShape_
[
i
],
ADD_TO
);
BACKWARD_FILTER
(
i
,
inputs
,
outputs
);
/* Increasing the number of gradient */
weights_
[
i
]
->
getParameterPtr
()
->
incUpdate
(
callback
);
}
}
}
}
// namespace paddle
paddle/gserver/layers/DepthwiseConvLayer.h
浏览文件 @
198164ad
...
...
@@ -15,7 +15,7 @@ limitations under the License. */
#pragma once
#include <vector>
#include "ExpandConv
Base
Layer.h"
#include "ExpandConvLayer.h"
#include "paddle/math/Matrix.h"
namespace
paddle
{
...
...
@@ -26,25 +26,15 @@ namespace paddle {
* The config file api is img_depthwise_conv_layer.
*/
class
DepthwiseConvLayer
:
public
ExpandConv
Base
Layer
{
class
DepthwiseConvLayer
:
public
ExpandConvLayer
{
public:
explicit
DepthwiseConvLayer
(
const
LayerConfig
&
config
)
:
ExpandConv
Base
Layer
(
config
)
{}
:
ExpandConvLayer
(
config
)
{}
~
DepthwiseConvLayer
()
{}
bool
init
(
const
LayerMap
&
layerMap
,
const
ParameterMap
&
parameterMap
)
override
;
void
forward
(
PassType
passType
)
override
;
void
backward
(
const
UpdateCallback
&
callback
)
override
;
protected:
std
::
vector
<
TensorShape
>
inputShape_
;
std
::
vector
<
TensorShape
>
filterShape_
;
std
::
vector
<
TensorShape
>
outputShape_
;
std
::
vector
<
TensorShape
>
multiplierShape_
;
std
::
vector
<
MatrixPtr
>
weightMultiplier_
;
};
}
// namespace paddle
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录