Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
f53beedd
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看板
未验证
提交
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. */
...
@@ -20,10 +20,8 @@ limitations under the License. */
#include "paddle/math/MathUtils.h"
#include "paddle/math/MathUtils.h"
#include "paddle/testing/TestUtil.h"
#include "paddle/testing/TestUtil.h"
using
namespace
paddle
;
void
setPoolConfig
(
paddle
::
TestConfig
*
config
,
paddle
::
PoolConfig
*
pool
,
void
setPoolConfig
(
TestConfig
*
config
,
PoolConfig
*
pool
,
const
string
&
poolType
)
{
const
string
&
poolType
)
{
(
*
config
).
biasSize
=
0
;
(
*
config
).
biasSize
=
0
;
(
*
config
).
layerConfig
.
set_type
(
"pool"
);
(
*
config
).
layerConfig
.
set_type
(
"pool"
);
...
@@ -42,21 +40,23 @@ void setPoolConfig(TestConfig* config,
...
@@ -42,21 +40,23 @@ void setPoolConfig(TestConfig* config,
pool
->
set_stride
(
sw
);
pool
->
set_stride
(
sw
);
pool
->
set_stride_y
(
sh
);
pool
->
set_stride_y
(
sh
);
int
ow
=
outputSize
(
pool
->
img_size
(),
kw
,
pw
,
sw
,
/* caffeMode */
false
);
int
ow
=
int
oh
=
outputSize
(
pool
->
img_size_y
(),
kh
,
ph
,
sh
,
/* caffeMode */
false
);
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_x
(
ow
);
pool
->
set_output_y
(
oh
);
pool
->
set_output_y
(
oh
);
}
}
LayerPtr
doOneUpsampleTest
(
MatrixPtr
&
inputMat
,
paddle
::
LayerPtr
doOneUpsampleTest
(
const
paddle
::
MatrixPtr
&
inputMat
,
const
string
&
poolType
,
const
string
&
poolType
,
bool
use_gpu
,
bool
use_gpu
,
real
*
tempGradData
)
{
real
*
tempGradData
)
{
/* prepare maxPoolWithMaskLayer */
/* prepare maxPoolWithMaskLayer */
TestConfig
config
;
paddle
::
TestConfig
config
;
config
.
inputDefs
.
push_back
({
INPUT_DATA
,
"layer_0"
,
128
,
0
});
config
.
inputDefs
.
push_back
({
paddle
::
INPUT_DATA
,
"layer_0"
,
128
,
0
});
LayerInputConfig
*
input
=
config
.
layerConfig
.
add_inputs
();
paddle
::
LayerInputConfig
*
input
=
config
.
layerConfig
.
add_inputs
();
PoolConfig
*
pool
=
input
->
mutable_pool_conf
();
paddle
::
PoolConfig
*
pool
=
input
->
mutable_pool_conf
();
pool
->
set_img_size
(
8
);
pool
->
set_img_size
(
8
);
pool
->
set_img_size_y
(
8
);
pool
->
set_img_size_y
(
8
);
...
@@ -66,9 +66,9 @@ LayerPtr doOneUpsampleTest(MatrixPtr& inputMat,
...
@@ -66,9 +66,9 @@ LayerPtr doOneUpsampleTest(MatrixPtr& inputMat,
config
.
layerConfig
.
set_name
(
"MaxPoolWithMask"
);
config
.
layerConfig
.
set_name
(
"MaxPoolWithMask"
);
std
::
vector
<
DataLayerPtr
>
dataLayers
;
std
::
vector
<
paddle
::
DataLayerPtr
>
dataLayers
;
LayerMap
layerMap
;
paddle
::
LayerMap
layerMap
;
vector
<
Argument
>
datas
;
vector
<
paddle
::
Argument
>
datas
;
initDataLayer
(
config
,
initDataLayer
(
config
,
&
dataLayers
,
&
dataLayers
,
...
@@ -82,20 +82,20 @@ LayerPtr doOneUpsampleTest(MatrixPtr& inputMat,
...
@@ -82,20 +82,20 @@ LayerPtr doOneUpsampleTest(MatrixPtr& inputMat,
dataLayers
[
0
]
->
getOutputValue
()
->
copyFrom
(
*
inputMat
);
dataLayers
[
0
]
->
getOutputValue
()
->
copyFrom
(
*
inputMat
);
FLAGS_use_gpu
=
use_gpu
;
FLAGS_use_gpu
=
use_gpu
;
std
::
vector
<
ParameterPtr
>
parameters
;
std
::
vector
<
paddle
::
ParameterPtr
>
parameters
;
LayerPtr
maxPoolingWithMaskOutputLayer
;
paddle
::
LayerPtr
maxPoolingWithMaskOutputLayer
;
initTestLayer
(
config
,
&
layerMap
,
&
parameters
,
&
maxPoolingWithMaskOutputLayer
);
initTestLayer
(
config
,
&
layerMap
,
&
parameters
,
&
maxPoolingWithMaskOutputLayer
);
maxPoolingWithMaskOutputLayer
->
forward
(
PASS_GC
);
maxPoolingWithMaskOutputLayer
->
forward
(
paddle
::
PASS_GC
);
/* prepare the upsample layer */
/* prepare the upsample layer */
LayerConfig
upsampleLayerConfig
;
paddle
::
LayerConfig
upsampleLayerConfig
;
upsampleLayerConfig
.
set_type
(
"upsample"
);
upsampleLayerConfig
.
set_type
(
"upsample"
);
LayerInputConfig
*
input1
=
upsampleLayerConfig
.
add_inputs
();
paddle
::
LayerInputConfig
*
input1
=
upsampleLayerConfig
.
add_inputs
();
upsampleLayerConfig
.
add_inputs
();
upsampleLayerConfig
.
add_inputs
();
UpsampleConfig
*
upsampleConfig
=
input1
->
mutable_upsample_conf
();
paddle
::
UpsampleConfig
*
upsampleConfig
=
input1
->
mutable_upsample_conf
();
upsampleConfig
->
set_scale
(
2
);
upsampleConfig
->
set_scale
(
2
);
ImageConfig
*
imageConfig
=
upsampleConfig
->
mutable_image_conf
();
paddle
::
ImageConfig
*
imageConfig
=
upsampleConfig
->
mutable_image_conf
();
imageConfig
->
set_channels
(
2
);
imageConfig
->
set_channels
(
2
);
imageConfig
->
set_img_size
(
4
);
imageConfig
->
set_img_size
(
4
);
imageConfig
->
set_img_size_y
(
4
);
imageConfig
->
set_img_size_y
(
4
);
...
@@ -103,17 +103,18 @@ LayerPtr doOneUpsampleTest(MatrixPtr& inputMat,
...
@@ -103,17 +103,18 @@ LayerPtr doOneUpsampleTest(MatrixPtr& inputMat,
upsampleLayerConfig
.
set_name
(
"upsample"
);
upsampleLayerConfig
.
set_name
(
"upsample"
);
for
(
size_t
i
=
0
;
i
<
2
;
i
++
)
{
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"
);
inputTemp
.
set_input_layer_name
(
"MaxPoolWithMask"
);
}
}
LayerPtr
upsampleLayer
;
paddle
::
LayerPtr
upsampleLayer
;
ParameterMap
parameterMap
;
paddle
::
ParameterMap
parameterMap
;
upsampleLayer
=
Layer
::
create
(
upsampleLayerConfig
);
upsampleLayer
=
paddle
::
Layer
::
create
(
upsampleLayerConfig
);
layerMap
[
upsampleLayerConfig
.
name
()]
=
upsampleLayer
;
layerMap
[
upsampleLayerConfig
.
name
()]
=
upsampleLayer
;
upsampleLayer
->
init
(
layerMap
,
parameterMap
);
upsampleLayer
->
init
(
layerMap
,
parameterMap
);
upsampleLayer
->
setNeedGradient
(
true
);
upsampleLayer
->
setNeedGradient
(
true
);
upsampleLayer
->
forward
(
PASS_GC
);
upsampleLayer
->
forward
(
paddle
::
PASS_GC
);
upsampleLayer
->
getOutputGrad
()
->
copyFrom
(
tempGradData
,
128
);
upsampleLayer
->
getOutputGrad
()
->
copyFrom
(
tempGradData
,
128
);
upsampleLayer
->
backward
();
upsampleLayer
->
backward
();
...
@@ -122,31 +123,31 @@ LayerPtr doOneUpsampleTest(MatrixPtr& inputMat,
...
@@ -122,31 +123,31 @@ LayerPtr doOneUpsampleTest(MatrixPtr& inputMat,
TEST
(
Layer
,
maxPoolingWithMaskOutputLayerFwd
)
{
TEST
(
Layer
,
maxPoolingWithMaskOutputLayerFwd
)
{
bool
useGpu
=
false
;
bool
useGpu
=
false
;
MatrixPtr
inputMat
;
paddle
::
MatrixPtr
inputMat
;
MatrixPtr
inputGPUMat
;
paddle
::
MatrixPtr
inputGPUMat
;
MatrixPtr
tempGradMat
;
paddle
::
MatrixPtr
tempGradMat
;
inputMat
=
Matrix
::
create
(
1
,
128
,
false
,
useGpu
);
inputMat
=
paddle
::
Matrix
::
create
(
1
,
128
,
false
,
useGpu
);
inputMat
->
randomizeUniform
();
inputMat
->
randomizeUniform
();
tempGradMat
=
Matrix
::
create
(
1
,
128
,
false
,
useGpu
);
tempGradMat
=
paddle
::
Matrix
::
create
(
1
,
128
,
false
,
useGpu
);
tempGradMat
->
randomizeUniform
();
tempGradMat
->
randomizeUniform
();
real
*
data
=
inputMat
->
getData
();
real
*
tempGradData
=
tempGradMat
->
getData
();
real
*
tempGradData
=
tempGradMat
->
getData
();
LayerPtr
upsampleLayerCPU
=
paddle
::
LayerPtr
upsampleLayerCPU
=
doOneUpsampleTest
(
inputMat
,
"max-pool-with-mask"
,
useGpu
,
tempGradData
);
doOneUpsampleTest
(
inputMat
,
"max-pool-with-mask"
,
useGpu
,
tempGradData
);
#ifdef PADDLE_WITH_CUDA
#ifdef PADDLE_WITH_CUDA
useGpu
=
true
;
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
);
inputGPUMat
->
copyFrom
(
data
,
128
);
LayerPtr
upsampleLayerGPU
=
doOneUpsampleTest
(
paddle
::
LayerPtr
upsampleLayerGPU
=
doOneUpsampleTest
(
inputGPUMat
,
"max-pool-with-mask"
,
useGpu
,
tempGradData
);
inputGPUMat
,
"max-pool-with-mask"
,
useGpu
,
tempGradData
);
checkMatrixEqual
(
upsampleLayerCPU
->
getOutput
(
""
).
value
,
paddle
::
checkMatrixEqual
(
upsampleLayerCPU
->
getOutput
(
""
).
value
,
upsampleLayerGPU
->
getOutput
(
""
).
value
);
upsampleLayerGPU
->
getOutput
(
""
).
value
);
checkMatrixEqual
(
upsampleLayerCPU
->
getPrev
(
0
)
->
getOutputGrad
(),
paddle
::
checkMatrixEqual
(
upsampleLayerCPU
->
getPrev
(
0
)
->
getOutputGrad
(),
upsampleLayerGPU
->
getPrev
(
0
)
->
getOutputGrad
());
upsampleLayerGPU
->
getPrev
(
0
)
->
getOutputGrad
());
#endif
#endif
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录