Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
424b325d
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看板
提交
424b325d
编写于
8月 18, 2017
作者:
C
chengduoZH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add unit test DeConv3D, Conv3D, col2vol, vol2col
上级
9b3d6acd
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
268 addition
and
0 deletion
+268
-0
paddle/gserver/tests/test_LayerGrad.cpp
paddle/gserver/tests/test_LayerGrad.cpp
+152
-0
paddle/math/tests/test_matrixCompare.cpp
paddle/math/tests/test_matrixCompare.cpp
+116
-0
未找到文件。
paddle/gserver/tests/test_LayerGrad.cpp
浏览文件 @
424b325d
...
...
@@ -2007,6 +2007,158 @@ TEST(Layer, RowL2NormLayer) {
}
}
void
test3DConvLayer
(
const
string
&
type
,
bool
trans
,
bool
useGpu
)
{
// filter size
const
int
NUM_FILTERS
=
6
;
// const int CHANNELS = 3;
const
int
FILTER_SIZE
=
3
;
const
int
FILTER_SIZE_Y
=
3
;
const
int
FILTER_SIZE_Z
=
3
;
// input image
const
int
CHANNELS
=
3
;
const
int
IMAGE_SIZE
=
9
;
const
int
IMAGE_SIZE_Y
=
9
;
const
int
IMAGE_SIZE_Z
=
9
;
// 2, 3, 5, 5, 5
TestConfig
config
;
config
.
biasSize
=
NUM_FILTERS
;
config
.
layerConfig
.
set_type
(
type
);
config
.
layerConfig
.
set_num_filters
(
NUM_FILTERS
);
config
.
layerConfig
.
set_partial_sum
(
1
);
config
.
layerConfig
.
set_shared_biases
(
true
);
// Setting up conv3D-trans layer
LayerInputConfig
*
input
=
config
.
layerConfig
.
add_inputs
();
ConvConfig
*
conv
=
input
->
mutable_conv_conf
();
conv
->
set_channels
(
CHANNELS
);
conv
->
set_filter_size
(
FILTER_SIZE
);
conv
->
set_filter_size_y
(
FILTER_SIZE_Y
);
conv
->
set_filter_size_z
(
FILTER_SIZE_Z
);
conv
->
set_padding
(
0
);
conv
->
set_padding_y
(
0
);
conv
->
set_padding_z
(
0
);
conv
->
set_stride
(
2
);
conv
->
set_stride_y
(
2
);
conv
->
set_stride_z
(
2
);
conv
->
set_img_size
(
IMAGE_SIZE
);
conv
->
set_img_size_y
(
IMAGE_SIZE_Y
);
conv
->
set_img_size_z
(
IMAGE_SIZE_Z
);
conv
->
set_output_x
(
outputSize
(
conv
->
img_size
(),
conv
->
filter_size
(),
conv
->
padding
(),
conv
->
stride
(),
/* caffeMode */
true
));
conv
->
set_output_y
(
outputSize
(
conv
->
img_size_y
(),
conv
->
filter_size_y
(),
conv
->
padding_y
(),
conv
->
stride_y
(),
/* caffeMode */
true
));
conv
->
set_output_z
(
outputSize
(
conv
->
img_size_z
(),
conv
->
filter_size_z
(),
conv
->
padding_z
(),
conv
->
stride_z
(),
/* caffeMode */
true
));
config
.
layerConfig
.
set_size
(
conv
->
output_x
()
*
conv
->
output_y
()
*
conv
->
output_z
()
*
NUM_FILTERS
);
conv
->
set_groups
(
1
);
conv
->
set_filter_channels
(
conv
->
channels
()
/
conv
->
groups
());
config
.
inputDefs
.
push_back
(
{
INPUT_DATA
,
"layer_0"
,
CHANNELS
*
IMAGE_SIZE
*
IMAGE_SIZE_Y
*
IMAGE_SIZE_Z
,
conv
->
filter_channels
()
*
FILTER_SIZE
*
FILTER_SIZE_Y
*
FILTER_SIZE_Z
*
NUM_FILTERS
});
testLayerGrad
(
config
,
"conv3D"
,
10
,
trans
,
useGpu
);
// Use small batch_size and useWeight=true to test biasGrad
testLayerGrad
(
config
,
"conv3D"
,
2
,
trans
,
useGpu
,
true
,
0.02
);
}
TEST
(
Layer
,
test3DConvLayer
)
{
test3DConvLayer
(
"conv3d"
,
/* trans= */
false
,
/* useGpu= */
false
);
#ifndef PADDLE_ONLY_CPU
test3DConvLayer
(
"conv3d"
,
/* trans= */
false
,
/* useGpu= */
true
);
#endif
}
int
deConvOutputSize
(
int
inSize
,
int
kSize
,
int
pad
,
int
stride
)
{
return
(
inSize
-
1
)
*
stride
-
2
*
pad
+
kSize
;
}
void
test3DDeConvLayer
(
const
string
&
type
,
bool
trans
,
bool
useGpu
)
{
// filter size
const
int
NUM_FILTERS
=
6
;
// const int CHANNELS = 3;
const
int
FILTER_SIZE
=
3
;
const
int
FILTER_SIZE_Y
=
3
;
const
int
FILTER_SIZE_Z
=
3
;
// input image
const
int
CHANNELS
=
3
;
const
int
IMAGE_SIZE
=
4
;
const
int
IMAGE_SIZE_Y
=
6
;
const
int
IMAGE_SIZE_Z
=
6
;
// Setting up conv-trans layer
TestConfig
config
;
config
.
biasSize
=
NUM_FILTERS
;
config
.
layerConfig
.
set_type
(
"deconv3d"
);
config
.
layerConfig
.
set_num_filters
(
NUM_FILTERS
);
config
.
layerConfig
.
set_partial_sum
(
1
);
config
.
layerConfig
.
set_shared_biases
(
true
);
LayerInputConfig
*
input
=
config
.
layerConfig
.
add_inputs
();
ConvConfig
*
conv
=
input
->
mutable_conv_conf
();
conv
->
set_channels
(
CHANNELS
);
conv
->
set_filter_size
(
FILTER_SIZE
);
conv
->
set_filter_size_y
(
FILTER_SIZE_Y
);
conv
->
set_filter_size_z
(
FILTER_SIZE_Z
);
conv
->
set_padding
(
0
);
conv
->
set_padding_y
(
0
);
conv
->
set_padding_z
(
0
);
conv
->
set_stride
(
2
);
conv
->
set_stride_y
(
2
);
conv
->
set_stride_z
(
2
);
conv
->
set_img_size
(
IMAGE_SIZE
);
conv
->
set_img_size_y
(
IMAGE_SIZE_Y
);
conv
->
set_img_size_z
(
IMAGE_SIZE_Z
);
conv
->
set_output_x
(
deConvOutputSize
(
conv
->
img_size
(),
conv
->
filter_size
(),
conv
->
padding
(),
conv
->
stride
()));
conv
->
set_output_y
(
deConvOutputSize
(
conv
->
img_size_y
(),
conv
->
filter_size_y
(),
conv
->
padding_y
(),
conv
->
stride_y
()));
conv
->
set_output_z
(
deConvOutputSize
(
conv
->
img_size_z
(),
conv
->
filter_size_z
(),
conv
->
padding_z
(),
conv
->
stride_z
()));
config
.
layerConfig
.
set_size
(
conv
->
output_x
()
*
conv
->
output_y
()
*
conv
->
output_z
()
*
NUM_FILTERS
);
conv
->
set_groups
(
1
);
conv
->
set_filter_channels
(
conv
->
channels
()
/
conv
->
groups
());
config
.
inputDefs
.
push_back
(
{
INPUT_DATA
,
"layer_0"
,
CHANNELS
*
IMAGE_SIZE
*
IMAGE_SIZE_Y
*
IMAGE_SIZE_Z
,
conv
->
filter_channels
()
*
FILTER_SIZE
*
FILTER_SIZE_Y
*
FILTER_SIZE_Z
*
NUM_FILTERS
});
testLayerGrad
(
config
,
"deconv3D"
,
10
,
trans
,
useGpu
);
// Use small batch_size and useWeight=true to test biasGrad
testLayerGrad
(
config
,
"deconv3D"
,
2
,
trans
,
useGpu
,
true
,
0.02
);
}
TEST
(
Layer
,
test3DDeConvLayer
)
{
test3DDeConvLayer
(
"deconv3d"
,
/* trans= */
false
,
/* useGpu= */
false
);
#ifndef PADDLE_ONLY_CPU
test3DDeConvLayer
(
"deconv3d"
,
/* trans= */
false
,
/* useGpu= */
true
);
#endif
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
initMain
(
argc
,
argv
);
...
...
paddle/math/tests/test_matrixCompare.cpp
浏览文件 @
424b325d
...
...
@@ -1203,4 +1203,120 @@ TEST(Matrix, warpCTC) {
}
}
int
outputSizeCol2Vol
(
int
imageSize
,
int
filterSize
,
int
padding
,
int
stride
,
bool
caffeMode
)
{
int
outputSize
;
if
(
!
caffeMode
)
{
outputSize
=
(
imageSize
-
filterSize
+
2
*
padding
+
stride
-
1
)
/
stride
+
1
;
}
else
{
outputSize
=
(
imageSize
-
filterSize
+
2
*
padding
)
/
stride
+
1
;
}
CHECK_GE
(
outputSize
,
1
);
return
outputSize
;
}
void
testMatrixCol2Vol
(
int
depth
,
int
height
,
int
width
)
{
int
channel
=
3
;
int
filterX
=
3
,
filterY
=
4
,
filterZ
=
5
;
int
strideX
=
2
,
strideY
=
2
,
strideZ
=
2
;
int
padX
=
1
,
padY
=
1
,
padZ
=
1
;
MatrixPtr
cpuImage
=
std
::
make_shared
<
CpuMatrix
>
(
channel
,
depth
*
height
*
width
);
MatrixPtr
gpuImage
=
std
::
make_shared
<
GpuMatrix
>
(
channel
,
depth
*
height
*
width
);
cpuImage
->
randomizeUniform
();
gpuImage
->
copyFrom
(
*
cpuImage
);
int
outD
=
outputSizeCol2Vol
(
depth
,
filterZ
,
padZ
,
strideZ
,
true
);
int
outH
=
outputSizeCol2Vol
(
height
,
filterY
,
padZ
,
strideY
,
true
);
int
outW
=
outputSizeCol2Vol
(
width
,
filterX
,
padZ
,
strideX
,
true
);
int
colBufHeight
=
channel
*
filterZ
*
filterY
*
filterX
;
int
colBufWidth
=
outD
*
outH
*
outW
;
MatrixPtr
cpuColBuf
=
std
::
make_shared
<
CpuMatrix
>
(
colBufHeight
,
colBufWidth
);
MatrixPtr
gpuColBuf
=
std
::
make_shared
<
GpuMatrix
>
(
colBufHeight
,
colBufWidth
);
cpuColBuf
->
vol2Col
(
cpuImage
->
getData
(),
channel
,
depth
,
height
,
width
,
filterZ
,
filterY
,
filterX
,
strideZ
,
strideY
,
strideX
,
padZ
,
padY
,
padX
);
gpuColBuf
->
vol2Col
(
gpuImage
->
getData
(),
channel
,
depth
,
height
,
width
,
filterZ
,
filterY
,
filterX
,
strideZ
,
strideY
,
strideX
,
padZ
,
padY
,
padX
);
TensorCheckEqual
(
*
cpuColBuf
,
*
gpuColBuf
);
cpuColBuf
->
randomizeUniform
();
gpuColBuf
->
copyFrom
(
*
cpuColBuf
);
cpuColBuf
->
col2Vol
(
cpuImage
->
getData
(),
channel
,
depth
,
height
,
width
,
filterZ
,
filterY
,
filterX
,
strideZ
,
strideY
,
strideX
,
padZ
,
padY
,
padX
,
1.0
,
1.0
);
gpuColBuf
->
col2Vol
(
gpuImage
->
getData
(),
channel
,
depth
,
height
,
width
,
filterZ
,
filterY
,
filterX
,
strideZ
,
strideY
,
strideX
,
padZ
,
padY
,
padX
,
1.0
,
1.0
);
TensorCheckErr
(
*
cpuImage
,
*
gpuImage
);
}
TEST
(
Matrix
,
col2Vol
)
{
for
(
auto
depth
:
{
9
,
16
,
64
,
128
})
{
for
(
auto
height
:
{
9
,
11
,
73
,
128
,
256
})
{
for
(
auto
width
:
{
9
,
32
,
100
,
512
,
})
{
VLOG
(
3
)
<<
"depth="
<<
depth
<<
" height="
<<
height
<<
" width="
<<
width
;
testMatrixCol2Vol
(
depth
,
height
,
width
);
}
}
}
}
///////
#endif
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录