Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f53beedd
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f53beedd
编写于
4月 06, 2018
作者:
A
Abhinav Arora
提交者:
GitHub
4月 06, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix issue 9673 (#9674)
上级
b5b7ea12
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
43 addition
and
42 deletion
+43
-42
paddle/gserver/tests/test_Upsample.cpp
paddle/gserver/tests/test_Upsample.cpp
+43
-42
未找到文件。
paddle/gserver/tests/test_Upsample.cpp
浏览文件 @
f53beedd
...
...
@@ -20,10 +20,8 @@ limitations under the License. */
#include "paddle/math/MathUtils.h"
#include "paddle/testing/TestUtil.h"
using
namespace
paddle
;
void
setPoolConfig
(
TestConfig
*
config
,
PoolConfig
*
pool
,
void
setPoolConfig
(
paddle
::
TestConfig
*
config
,
paddle
::
PoolConfig
*
pool
,
const
string
&
poolType
)
{
(
*
config
).
biasSize
=
0
;
(
*
config
).
layerConfig
.
set_type
(
"pool"
);
...
...
@@ -42,21 +40,23 @@ void setPoolConfig(TestConfig* config,
pool
->
set_stride
(
sw
);
pool
->
set_stride_y
(
sh
);
int
ow
=
outputSize
(
pool
->
img_size
(),
kw
,
pw
,
sw
,
/* caffeMode */
false
);
int
oh
=
outputSize
(
pool
->
img_size_y
(),
kh
,
ph
,
sh
,
/* caffeMode */
false
);
int
ow
=
paddle
::
outputSize
(
pool
->
img_size
(),
kw
,
pw
,
sw
,
/* caffeMode */
false
);
int
oh
=
paddle
::
outputSize
(
pool
->
img_size_y
(),
kh
,
ph
,
sh
,
/* caffeMode */
false
);
pool
->
set_output_x
(
ow
);
pool
->
set_output_y
(
oh
);
}
LayerPtr
doOneUpsampleTest
(
MatrixPtr
&
inputMat
,
paddle
::
LayerPtr
doOneUpsampleTest
(
const
paddle
::
MatrixPtr
&
inputMat
,
const
string
&
poolType
,
bool
use_gpu
,
real
*
tempGradData
)
{
/* prepare maxPoolWithMaskLayer */
TestConfig
config
;
config
.
inputDefs
.
push_back
({
INPUT_DATA
,
"layer_0"
,
128
,
0
});
LayerInputConfig
*
input
=
config
.
layerConfig
.
add_inputs
();
PoolConfig
*
pool
=
input
->
mutable_pool_conf
();
paddle
::
TestConfig
config
;
config
.
inputDefs
.
push_back
({
paddle
::
INPUT_DATA
,
"layer_0"
,
128
,
0
});
paddle
::
LayerInputConfig
*
input
=
config
.
layerConfig
.
add_inputs
();
paddle
::
PoolConfig
*
pool
=
input
->
mutable_pool_conf
();
pool
->
set_img_size
(
8
);
pool
->
set_img_size_y
(
8
);
...
...
@@ -66,9 +66,9 @@ LayerPtr doOneUpsampleTest(MatrixPtr& inputMat,
config
.
layerConfig
.
set_name
(
"MaxPoolWithMask"
);
std
::
vector
<
DataLayerPtr
>
dataLayers
;
LayerMap
layerMap
;
vector
<
Argument
>
datas
;
std
::
vector
<
paddle
::
DataLayerPtr
>
dataLayers
;
paddle
::
LayerMap
layerMap
;
vector
<
paddle
::
Argument
>
datas
;
initDataLayer
(
config
,
&
dataLayers
,
...
...
@@ -82,20 +82,20 @@ LayerPtr doOneUpsampleTest(MatrixPtr& inputMat,
dataLayers
[
0
]
->
getOutputValue
()
->
copyFrom
(
*
inputMat
);
FLAGS_use_gpu
=
use_gpu
;
std
::
vector
<
ParameterPtr
>
parameters
;
LayerPtr
maxPoolingWithMaskOutputLayer
;
std
::
vector
<
paddle
::
ParameterPtr
>
parameters
;
paddle
::
LayerPtr
maxPoolingWithMaskOutputLayer
;
initTestLayer
(
config
,
&
layerMap
,
&
parameters
,
&
maxPoolingWithMaskOutputLayer
);
maxPoolingWithMaskOutputLayer
->
forward
(
PASS_GC
);
maxPoolingWithMaskOutputLayer
->
forward
(
paddle
::
PASS_GC
);
/* prepare the upsample layer */
LayerConfig
upsampleLayerConfig
;
paddle
::
LayerConfig
upsampleLayerConfig
;
upsampleLayerConfig
.
set_type
(
"upsample"
);
LayerInputConfig
*
input1
=
upsampleLayerConfig
.
add_inputs
();
paddle
::
LayerInputConfig
*
input1
=
upsampleLayerConfig
.
add_inputs
();
upsampleLayerConfig
.
add_inputs
();
UpsampleConfig
*
upsampleConfig
=
input1
->
mutable_upsample_conf
();
paddle
::
UpsampleConfig
*
upsampleConfig
=
input1
->
mutable_upsample_conf
();
upsampleConfig
->
set_scale
(
2
);
ImageConfig
*
imageConfig
=
upsampleConfig
->
mutable_image_conf
();
paddle
::
ImageConfig
*
imageConfig
=
upsampleConfig
->
mutable_image_conf
();
imageConfig
->
set_channels
(
2
);
imageConfig
->
set_img_size
(
4
);
imageConfig
->
set_img_size_y
(
4
);
...
...
@@ -103,17 +103,18 @@ LayerPtr doOneUpsampleTest(MatrixPtr& inputMat,
upsampleLayerConfig
.
set_name
(
"upsample"
);
for
(
size_t
i
=
0
;
i
<
2
;
i
++
)
{
LayerInputConfig
&
inputTemp
=
*
(
upsampleLayerConfig
.
mutable_inputs
(
i
));
paddle
::
LayerInputConfig
&
inputTemp
=
*
(
upsampleLayerConfig
.
mutable_inputs
(
i
));
inputTemp
.
set_input_layer_name
(
"MaxPoolWithMask"
);
}
LayerPtr
upsampleLayer
;
ParameterMap
parameterMap
;
upsampleLayer
=
Layer
::
create
(
upsampleLayerConfig
);
paddle
::
LayerPtr
upsampleLayer
;
paddle
::
ParameterMap
parameterMap
;
upsampleLayer
=
paddle
::
Layer
::
create
(
upsampleLayerConfig
);
layerMap
[
upsampleLayerConfig
.
name
()]
=
upsampleLayer
;
upsampleLayer
->
init
(
layerMap
,
parameterMap
);
upsampleLayer
->
setNeedGradient
(
true
);
upsampleLayer
->
forward
(
PASS_GC
);
upsampleLayer
->
forward
(
paddle
::
PASS_GC
);
upsampleLayer
->
getOutputGrad
()
->
copyFrom
(
tempGradData
,
128
);
upsampleLayer
->
backward
();
...
...
@@ -122,31 +123,31 @@ LayerPtr doOneUpsampleTest(MatrixPtr& inputMat,
TEST
(
Layer
,
maxPoolingWithMaskOutputLayerFwd
)
{
bool
useGpu
=
false
;
MatrixPtr
inputMat
;
MatrixPtr
inputGPUMat
;
MatrixPtr
tempGradMat
;
paddle
::
MatrixPtr
inputMat
;
paddle
::
MatrixPtr
inputGPUMat
;
paddle
::
MatrixPtr
tempGradMat
;
inputMat
=
Matrix
::
create
(
1
,
128
,
false
,
useGpu
);
inputMat
=
paddle
::
Matrix
::
create
(
1
,
128
,
false
,
useGpu
);
inputMat
->
randomizeUniform
();
tempGradMat
=
Matrix
::
create
(
1
,
128
,
false
,
useGpu
);
tempGradMat
=
paddle
::
Matrix
::
create
(
1
,
128
,
false
,
useGpu
);
tempGradMat
->
randomizeUniform
();
real
*
data
=
inputMat
->
getData
();
real
*
tempGradData
=
tempGradMat
->
getData
();
LayerPtr
upsampleLayerCPU
=
paddle
::
LayerPtr
upsampleLayerCPU
=
doOneUpsampleTest
(
inputMat
,
"max-pool-with-mask"
,
useGpu
,
tempGradData
);
#ifdef PADDLE_WITH_CUDA
useGpu
=
true
;
inputGPUMat
=
Matrix
::
create
(
1
,
128
,
false
,
useGpu
);
real
*
data
=
inputMat
->
getData
();
inputGPUMat
=
paddle
::
Matrix
::
create
(
1
,
128
,
false
,
useGpu
);
inputGPUMat
->
copyFrom
(
data
,
128
);
LayerPtr
upsampleLayerGPU
=
doOneUpsampleTest
(
paddle
::
LayerPtr
upsampleLayerGPU
=
doOneUpsampleTest
(
inputGPUMat
,
"max-pool-with-mask"
,
useGpu
,
tempGradData
);
checkMatrixEqual
(
upsampleLayerCPU
->
getOutput
(
""
).
value
,
paddle
::
checkMatrixEqual
(
upsampleLayerCPU
->
getOutput
(
""
).
value
,
upsampleLayerGPU
->
getOutput
(
""
).
value
);
checkMatrixEqual
(
upsampleLayerCPU
->
getPrev
(
0
)
->
getOutputGrad
(),
paddle
::
checkMatrixEqual
(
upsampleLayerCPU
->
getPrev
(
0
)
->
getOutputGrad
(),
upsampleLayerGPU
->
getPrev
(
0
)
->
getOutputGrad
());
#endif
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录