Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
61aa1098
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
61aa1098
编写于
6月 13, 2017
作者:
H
hedaoyuan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
BlockExpandLayer based on the ImageExpand Function.
上级
48e0f432
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
60 addition
and
29 deletion
+60
-29
paddle/function/ImageExpandOp.cpp
paddle/function/ImageExpandOp.cpp
+8
-1
paddle/gserver/layers/BlockExpandLayer.cpp
paddle/gserver/layers/BlockExpandLayer.cpp
+52
-28
未找到文件。
paddle/function/ImageExpandOp.cpp
浏览文件 @
61aa1098
...
@@ -119,12 +119,17 @@ public:
...
@@ -119,12 +119,17 @@ public:
1
+
1
+
(
inputWidth
+
2
*
paddingW
()
-
blockW
()
+
strideW
()
-
1
)
/
strideW
();
(
inputWidth
+
2
*
paddingW
()
-
blockW
()
+
strideW
()
-
1
)
/
strideW
();
CHECK_EQ
(
seqLength
,
outputHeight
*
outputWidth
);
CHECK_EQ
(
seqLength
,
outputHeight
*
outputWidth
);
CHECK_EQ
(
stepSize
,
inputChannels
*
blockH
()
*
block
H
());
CHECK_EQ
(
stepSize
,
inputChannels
*
blockH
()
*
block
W
());
real
*
inputData
=
inputs
[
0
].
data
<
real
>
();
real
*
inputData
=
inputs
[
0
].
data
<
real
>
();
real
*
outputData
=
outputs
[
0
].
data
<
real
>
();
real
*
outputData
=
outputs
[
0
].
data
<
real
>
();
Im2ColFunctor
<
kOCF
,
Device
,
real
>
im2col
;
Im2ColFunctor
<
kOCF
,
Device
,
real
>
im2col
;
for
(
size_t
i
=
0
;
i
<
batchSize
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
batchSize
;
i
++
)
{
// The result of im2col is [output_height, output_width,
// input_channels, filter_height, filter_width], and it is easy to
// reshape into [seqLength, stepSize], where seqLength is equal
// output_height * output_width, stepSize is equal
// input_channels * filter_height * filter_width
im2col
(
inputData
,
im2col
(
inputData
,
inputChannels
,
inputChannels
,
inputHeight
,
inputHeight
,
...
@@ -161,4 +166,6 @@ protected:
...
@@ -161,4 +166,6 @@ protected:
inline
int
blockW
()
const
{
return
blocks_
[
1
];
}
inline
int
blockW
()
const
{
return
blocks_
[
1
];
}
};
};
REGISTER_TYPED_FUNC
(
ImageExpand
,
CPU
,
ImageExpandFunction
);
}
// namespace paddle
}
// namespace paddle
paddle/gserver/layers/BlockExpandLayer.cpp
浏览文件 @
61aa1098
...
@@ -37,6 +37,18 @@ bool BlockExpandLayer::init(const LayerMap& layerMap,
...
@@ -37,6 +37,18 @@ bool BlockExpandLayer::init(const LayerMap& layerMap,
imgSizeH_
=
blockConf
.
img_size_y
();
imgSizeH_
=
blockConf
.
img_size_y
();
imgSizeW_
=
blockConf
.
img_size_x
();
imgSizeW_
=
blockConf
.
img_size_x
();
if
(
!
useGpu_
)
{
std
::
vector
<
size_t
>
strides
=
{(
size_t
)
strideH_
,
(
size_t
)
strideW_
};
std
::
vector
<
size_t
>
paddings
=
{(
size_t
)
paddingH_
,
(
size_t
)
paddingW_
};
std
::
vector
<
size_t
>
blocks
=
{(
size_t
)
blockH_
,
(
size_t
)
blockW_
};
createFunction
(
forward_
,
"ImageExpand"
,
FuncConfig
()
.
set
(
"strides"
,
strides
)
.
set
(
"paddings"
,
paddings
)
.
set
(
"blocks"
,
blocks
));
}
return
true
;
return
true
;
}
}
...
@@ -63,10 +75,11 @@ void BlockExpandLayer::forward(PassType passType) {
...
@@ -63,10 +75,11 @@ void BlockExpandLayer::forward(PassType passType) {
Layer
::
forward
(
passType
);
Layer
::
forward
(
passType
);
size_t
batchSize
=
inputLayers_
[
0
]
->
getOutputValue
()
->
getHeight
();
size_t
batchSize
=
inputLayers_
[
0
]
->
getOutputValue
()
->
getHeight
();
size_t
blockNum
=
getBlockNum
();
size_t
blockNum
=
getBlockNum
();
size_t
blockSize
=
blockH_
*
blockW_
*
channels_
;
size_t
blockSize
=
blockH_
*
blockW_
*
channels_
;
resetOutput
(
blockNum
*
batchSize
,
blockSize
);
resetOutput
(
blockNum
*
batchSize
,
blockSize
);
// TODO(hedaoyuan): After completing the GPU version of ImageExpand,
// refactor the following code.
Argument
&
out
=
getOutput
();
Argument
&
out
=
getOutput
();
MatrixPtr
outV
=
getOutputValue
();
MatrixPtr
outV
=
getOutputValue
();
...
@@ -78,38 +91,49 @@ void BlockExpandLayer::forward(PassType passType) {
...
@@ -78,38 +91,49 @@ void BlockExpandLayer::forward(PassType passType) {
int
*
start
=
out
.
sequenceStartPositions
->
getMutableData
(
false
);
int
*
start
=
out
.
sequenceStartPositions
->
getMutableData
(
false
);
int
*
dims
=
out
.
cpuSequenceDims
->
getData
();
int
*
dims
=
out
.
cpuSequenceDims
->
getData
();
for
(
size_t
i
=
0
;
i
<
batchSize
;
i
++
)
{
for
(
size_t
i
=
0
;
i
<
batchSize
;
i
++
)
{
outVTrans_
->
zeroMem
();
if
(
useGpu_
)
{
/* expand each block as one row */
outVTrans_
->
zeroMem
();
MatrixPtr
inputTmp
=
/* expand each block as one row */
Matrix
::
create
(
input
->
getData
()
+
i
*
input
->
getWidth
(),
MatrixPtr
inputTmp
=
1
,
Matrix
::
create
(
input
->
getData
()
+
i
*
input
->
getWidth
(),
input
->
getWidth
(),
1
,
false
,
input
->
getWidth
(),
useGpu_
);
false
,
outVTrans_
->
convExpand
(
*
inputTmp
,
useGpu_
);
imgSizeH_
,
outVTrans_
->
convExpand
(
*
inputTmp
,
imgSizeW_
,
imgSizeH_
,
channels_
,
imgSizeW_
,
blockH_
,
channels_
,
blockW_
,
blockH_
,
strideH_
,
blockW_
,
strideW_
,
strideH_
,
paddingH_
,
strideW_
,
paddingW_
,
paddingH_
,
outputH_
,
paddingW_
,
outputW_
);
outputH_
,
MatrixPtr
outVTmp
=
outputW_
);
Matrix
::
create
(
outV
->
getData
()
+
i
*
blockNum
*
blockSize
,
MatrixPtr
outVTmp
=
blockNum
,
Matrix
::
create
(
outV
->
getData
()
+
i
*
blockNum
*
blockSize
,
blockSize
,
blockNum
,
false
,
blockSize
,
useGpu_
);
false
,
outVTrans_
->
transpose
(
outVTmp
,
false
);
useGpu_
);
outVTrans_
->
transpose
(
outVTmp
,
false
);
}
start
[
i
]
=
i
*
blockNum
;
start
[
i
]
=
i
*
blockNum
;
dims
[
2
*
i
]
=
outputH_
;
dims
[
2
*
i
]
=
outputH_
;
dims
[
2
*
i
+
1
]
=
outputW_
;
dims
[
2
*
i
+
1
]
=
outputW_
;
}
}
start
[
batchSize
]
=
batchSize
*
blockNum
;
start
[
batchSize
]
=
batchSize
*
blockNum
;
if
(
!
useGpu_
)
{
TensorShape
inputShape
({
batchSize
,
channels_
,
imgSizeH_
,
imgSizeW_
});
TensorShape
outputShape
({
batchSize
,
blockNum
,
blockSize
});
BufferArgs
inputs
;
BufferArgs
outputs
;
inputs
.
addArg
(
*
getInputValue
(
0
),
inputShape
);
outputs
.
addArg
(
*
getOutputValue
(),
outputShape
,
ASSIGN_TO
);
forward_
[
0
]
->
calc
(
inputs
,
outputs
);
}
}
}
void
BlockExpandLayer
::
backward
(
const
UpdateCallback
&
callback
)
{
void
BlockExpandLayer
::
backward
(
const
UpdateCallback
&
callback
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录