Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OPTHREE
Paddle
提交
8e6965be
P
Paddle
项目概览
OPTHREE
/
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看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8e6965be
编写于
11月 30, 2016
作者:
Y
Yi Wang
浏览文件
操作
浏览文件
下载
差异文件
Resolve conflict with upstream/develop
上级
bb13328e
257819d3
变更
14
显示空白变更内容
内联
并排
Showing
14 changed file
with
339 addition
and
58 deletion
+339
-58
doc_cn/build/docker/build_docker_image.rst
doc_cn/build/docker/build_docker_image.rst
+0
-38
doc_cn/howto/build_docker_image.rst
doc_cn/howto/build_docker_image.rst
+35
-0
doc_cn/index.rst
doc_cn/index.rst
+1
-0
paddle/gserver/layers/ConvProjection.cpp
paddle/gserver/layers/ConvProjection.cpp
+4
-3
paddle/gserver/layers/ExpandConvBaseLayer.cpp
paddle/gserver/layers/ExpandConvBaseLayer.cpp
+6
-6
paddle/gserver/tests/CMakeLists.txt
paddle/gserver/tests/CMakeLists.txt
+7
-0
paddle/gserver/tests/img_conv_a.conf
paddle/gserver/tests/img_conv_a.conf
+2
-1
paddle/gserver/tests/img_conv_b.conf
paddle/gserver/tests/img_conv_b.conf
+1
-1
paddle/gserver/tests/img_conv_c.conf
paddle/gserver/tests/img_conv_c.conf
+43
-0
paddle/gserver/tests/test_ConvUnify.cpp
paddle/gserver/tests/test_ConvUnify.cpp
+199
-0
paddle/gserver/tests/test_LayerGrad.cpp
paddle/gserver/tests/test_LayerGrad.cpp
+11
-5
paddle/gserver/tests/test_NetworkCompare.cpp
paddle/gserver/tests/test_NetworkCompare.cpp
+10
-0
python/paddle/trainer/config_parser.py
python/paddle/trainer/config_parser.py
+2
-1
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+18
-3
未找到文件。
doc_cn/build/docker/build_docker_image.rst
已删除
100644 → 0
浏览文件 @
bb13328e
构建PaddlePaddle Docker Image
===========================
PaddlePaddle的Docker Image构建源码放置在 :code:`${源码根目录}/paddle/scripts/docker/`目录下。
该Image基于ubuntu 14.04。该目录下有两个文件,Dockerfile和build.sh。其中:
* Dockerfile是docker image的主要描述文件。描述了Docker image的构建步骤、各种参数和维护
人员等等。
* build.sh是docker image的主要构建步骤。
该image的构建在docker 1.12版本测试通过, 低于docker 1.12版本的情况下并没有测试。主要由于旧版本
的docker可能缺乏 :code:`--build-arg` 参数,从而不能在运行编译命令的时候接受参数。
同时,该构建脚本充分考虑了网络不稳定的情况,对于cuda的Toolkit有断点续传和传输速度过小重启下载的
简单优化。
使用脚本构建PaddlePaddle Docker Image
-------------------------------------------
该脚本的使用方法是,进入该源码目录,执行 :code:`docker build .` 命令。可以使用
:code:`--build-arg` 传入的配置参数包括:
* LOWEST\_DL\_SPEED\: 多线程下载过程中,最低线程的下载速度(默认单位是Bytes,可以传入10K,
10M,或者10G这样的单位)。如果小于这个下载速度,那么这个下载线程将会关闭。所有的下载线程关闭时,
下载进程会重启。
* WITH\_GPU\: ON or OFF。是否开启GPU功能。注意,编译PaddlePaddle的GPU版本并不需要一定在具有GPU
的机器上进行。但是,运行PaddlePaddle的GPU版本一定要在具有CUDA的机器上运行。
简单的使用样例为\:
.. code-block:: bash
cd ${源码根目录}/paddle/scripts/docker/
docker build --build-arg LOWEST_DL_SPEED=50K\
--build-arg WITH_GPU=ON \
--tag paddle_gpu:latest .
即可在本地编译出PaddlePaddle的镜像。
doc_cn/howto/build_docker_image.rst
0 → 100644
浏览文件 @
8e6965be
构建PaddlePaddle的Docker Image
==============================
PaddlePaddle的Docker Image构建源码放置在 ``${源码根目录}/paddle/scripts/docker/`` 目录下。该目录有三类文件:
- Dockerfile:Docker Image的描述文件,包括构建步骤、各种参数和维护人员等。
- 一共维护了12个Dockerfile,Dockerfile.m4是它们的模板。
- PaddlePaddle中所有的Image都基于ubuntu 14.04。
- build.sh:Docker Image的构建脚本,使用方式见下一小节。
- generate.sh:通过Dockerfile.m4模板生成不同的Dockerfile。
使用脚本构建Docker Image
------------------------
进入源码目录,执行 ``docker build`` 命令,即可在本地编译出PaddlePaddle的镜像。简单的使用样例为
.. code-block:: bash
cd ${源码根目录}/paddle/scripts/docker/
docker build --build-arg LOWEST_DL_SPEED=50K\
--build-arg WITH_GPU=ON \
--tag paddle_gpu:latest .
其中,``--build-arg`` 传入的配置参数包括:
- LOWEST\_DL\_SPEED\: 在多线程下载过程中,设置下线线程的最低速度。
- 默认单位是Bytes,但可以传入10K、10M、或10G等这样的单位。
- 如果小于这个速度,那么这个线程将会关闭。当所有的线程都关闭了,那么下载进程将会重启。
- WITH\_GPU\: ON or OFF,是否开启GPU功能。注意,
- **编译** PaddlePaddle的GPU版本 **不一定** 要在具有GPU的机器上进行。
- **运行** PaddlePaddle的GPU版本 **一定** 要在具有GPU的机器上运行。
注意:所有Image的构建在Docker 1.12版本测试通过, 低于1.12的版本并没有测试。原因是旧版本可能缺乏 ``--build-arg`` 参数,从而不能在运行编译命令的时候接受参数。
doc_cn/index.rst
浏览文件 @
8e6965be
...
@@ -16,6 +16,7 @@ PaddlePaddle文档
...
@@ -16,6 +16,7 @@ PaddlePaddle文档
--------
--------
* `新写Layer <../doc/dev/new_layer/index.html>`_
* `新写Layer <../doc/dev/new_layer/index.html>`_
* `如何贡献文档 <howto/how_to_write_docs/index.html>`_
* `如何贡献文档 <howto/how_to_write_docs/index.html>`_
* `如何构建Docker Image <howto/build_docker_image.html>`_
算法教程
算法教程
--------
--------
...
...
paddle/gserver/layers/ConvProjection.cpp
浏览文件 @
8e6965be
...
@@ -59,7 +59,8 @@ void ConvProjection::getConvParams() {
...
@@ -59,7 +59,8 @@ void ConvProjection::getConvParams() {
void
ConvProjection
::
initCudnn
()
{
void
ConvProjection
::
initCudnn
()
{
hl_create_filter_descriptor
(
hl_create_filter_descriptor
(
&
filterDesc_
,
channels_
,
numFilters_
,
filterH_
,
filterW_
);
&
filterDesc_
,
channels_
/
groups_
,
numFilters_
/
groups_
,
filterH_
,
filterW_
);
hl_create_tensor_descriptor
(
&
inputDesc_
);
hl_create_tensor_descriptor
(
&
inputDesc_
);
hl_create_tensor_descriptor
(
&
outputDesc_
);
hl_create_tensor_descriptor
(
&
outputDesc_
);
hl_create_convolution_descriptor
(
&
convDesc_
,
hl_create_convolution_descriptor
(
&
convDesc_
,
...
@@ -86,7 +87,7 @@ void ConvProjection::initCudnn() {
...
@@ -86,7 +87,7 @@ void ConvProjection::initCudnn() {
void
ConvProjection
::
reshapeTensorDesc
(
int
batchSize
)
{
void
ConvProjection
::
reshapeTensorDesc
(
int
batchSize
)
{
hl_tensor_reshape
(
inputDesc_
,
hl_tensor_reshape
(
inputDesc_
,
batchSize
,
batchSize
,
channels_
,
channels_
/
groups_
,
imageH_
,
imageH_
,
imageW_
,
imageW_
,
channels_
*
imageH_
*
imageW_
,
channels_
*
imageH_
*
imageW_
,
...
@@ -115,7 +116,7 @@ void ConvProjection::reshapeTensorDesc(int batchSize) {
...
@@ -115,7 +116,7 @@ void ConvProjection::reshapeTensorDesc(int batchSize) {
hl_tensor_reshape
(
outputDesc_
,
hl_tensor_reshape
(
outputDesc_
,
batchSize
,
batchSize
,
numFilters_
,
numFilters_
/
groups_
,
outputH_
,
outputH_
,
outputW_
,
outputW_
,
nStride
,
nStride
,
...
...
paddle/gserver/layers/ExpandConvBaseLayer.cpp
浏览文件 @
8e6965be
...
@@ -145,7 +145,7 @@ void ExpandConvBaseLayer::expandFwdOnce(MatrixPtr image,
...
@@ -145,7 +145,7 @@ void ExpandConvBaseLayer::expandFwdOnce(MatrixPtr image,
real
*
expInData
=
expandInput_
->
getData
();
real
*
expInData
=
expandInput_
->
getData
();
for
(
int
g
=
0
;
g
<
groups_
[
inIdx
];
++
g
)
{
for
(
int
g
=
0
;
g
<
groups_
[
inIdx
];
++
g
)
{
MatrixPtr
A
=
MatrixPtr
A
=
Matrix
::
create
(
wgtData
,
sub
K
,
subM
,
tru
e
,
useGpu_
);
// mark transpose
Matrix
::
create
(
wgtData
,
sub
M
,
subK
,
fals
e
,
useGpu_
);
// mark transpose
MatrixPtr
B
=
Matrix
::
create
(
expInData
,
subK
,
subN
,
false
,
useGpu_
);
MatrixPtr
B
=
Matrix
::
create
(
expInData
,
subK
,
subN
,
false
,
useGpu_
);
MatrixPtr
C
=
Matrix
::
create
(
outData
,
subM
,
subN
,
false
,
useGpu_
);
MatrixPtr
C
=
Matrix
::
create
(
outData
,
subM
,
subN
,
false
,
useGpu_
);
C
->
mul
(
A
,
B
,
1
,
1
);
C
->
mul
(
A
,
B
,
1
,
1
);
...
@@ -182,7 +182,7 @@ void ExpandConvBaseLayer::bpropActs(MatrixPtr out,
...
@@ -182,7 +182,7 @@ void ExpandConvBaseLayer::bpropActs(MatrixPtr out,
// create temporary matrix
// create temporary matrix
MatrixPtr
C
=
Matrix
::
create
(
expandInData
,
subK
,
subN
,
false
,
useGpu_
);
MatrixPtr
C
=
Matrix
::
create
(
expandInData
,
subK
,
subN
,
false
,
useGpu_
);
MatrixPtr
B
=
Matrix
::
create
(
localGradData
,
subM
,
subN
,
false
,
useGpu_
);
MatrixPtr
B
=
Matrix
::
create
(
localGradData
,
subM
,
subN
,
false
,
useGpu_
);
MatrixPtr
A
=
Matrix
::
create
(
wgtData
,
sub
K
,
subM
,
fals
e
,
useGpu_
);
MatrixPtr
A
=
Matrix
::
create
(
wgtData
,
sub
M
,
subK
,
tru
e
,
useGpu_
);
C
->
mul
(
A
,
B
);
// mul
C
->
mul
(
A
,
B
);
// mul
// clear the temporary matrix
// clear the temporary matrix
...
@@ -247,10 +247,10 @@ void ExpandConvBaseLayer::bpropWeights(MatrixPtr image,
...
@@ -247,10 +247,10 @@ void ExpandConvBaseLayer::bpropWeights(MatrixPtr image,
// expand-mul one-group by one
// expand-mul one-group by one
for
(
int
g
=
0
;
g
<
groups_
[
inpIdx
];
g
++
)
{
for
(
int
g
=
0
;
g
<
groups_
[
inpIdx
];
g
++
)
{
MatrixPtr
A
=
Matrix
::
create
(
expandInData
,
subK
,
subN
,
fals
e
,
useGpu_
);
MatrixPtr
A
=
Matrix
::
create
(
expandInData
,
subK
,
subN
,
tru
e
,
useGpu_
);
MatrixPtr
B
=
Matrix
::
create
(
gradData
,
subM
,
subN
,
tru
e
,
useGpu_
);
MatrixPtr
B
=
Matrix
::
create
(
gradData
,
subM
,
subN
,
fals
e
,
useGpu_
);
MatrixPtr
C
=
Matrix
::
create
(
wGradData
,
sub
K
,
subM
,
false
,
useGpu_
);
MatrixPtr
C
=
Matrix
::
create
(
wGradData
,
sub
M
,
subK
,
false
,
useGpu_
);
C
->
mul
(
A
,
B
,
1
,
1
);
C
->
mul
(
B
,
A
,
1
,
1
);
A
->
clear
();
A
->
clear
();
B
->
clear
();
B
->
clear
();
...
...
paddle/gserver/tests/CMakeLists.txt
浏览文件 @
8e6965be
...
@@ -34,7 +34,14 @@ add_unittest_without_exec(test_ConvTrans
...
@@ -34,7 +34,14 @@ add_unittest_without_exec(test_ConvTrans
add_test
(
NAME test_ConvTrans
add_test
(
NAME test_ConvTrans
COMMAND test_ConvTrans
)
COMMAND test_ConvTrans
)
################# test_ConvUnify #######################
add_unittest_without_exec
(
test_ConvUnify
test_ConvUnify.cpp
LayerGradUtil.cpp
TestUtil.cpp
)
add_test
(
NAME test_ConvUnify
COMMAND test_ConvUnify
)
################## test_Evaluator #######################
################## test_Evaluator #######################
add_unittest
(
test_Evaluator
add_unittest
(
test_Evaluator
test_Evaluator.cpp
test_Evaluator.cpp
...
...
paddle/gserver/tests/img_conv_a.conf
浏览文件 @
8e6965be
...
@@ -34,6 +34,7 @@ conv = img_conv_layer(input=data, filter_size=1, filter_size_y=1,
...
@@ -34,6 +34,7 @@ conv = img_conv_layer(input=data, filter_size=1, filter_size_y=1,
num_channels
=
8
,
num_channels
=
8
,
num_filters
=
16
,
stride
=
1
,
num_filters
=
16
,
stride
=
1
,
bias_attr
=
True
,
bias_attr
=
True
,
act
=
LinearActivation
())
act
=
LinearActivation
(),
groups
=
2
)
outputs
(
concat
,
conv
)
outputs
(
concat
,
conv
)
paddle/gserver/tests/img_conv_b.conf
浏览文件 @
8e6965be
...
@@ -24,7 +24,7 @@ proj2 = conv_projection(input=data, filter_size=1, filter_size_y=1,
...
@@ -24,7 +24,7 @@ proj2 = conv_projection(input=data, filter_size=1, filter_size_y=1,
concat
=
concat_layer
(
input
=[
proj1
,
proj2
],
bias_attr
=
False
,
act
=
ReluActivation
())
concat
=
concat_layer
(
input
=[
proj1
,
proj2
],
bias_attr
=
False
,
act
=
ReluActivation
())
proj
=
conv_projection
(
input
=
data
,
filter_size
=
1
,
filter_size_y
=
1
,
proj
=
conv_projection
(
input
=
data
,
filter_size
=
1
,
filter_size_y
=
1
,
num_channels
=
8
,
num_filters
=
16
,
stride
=
1
)
num_channels
=
8
,
num_filters
=
16
,
stride
=
1
,
groups
=
2
)
with
mixed_layer
(
bias_attr
=
True
,
act
=
LinearActivation
())
as
conv
:
with
mixed_layer
(
bias_attr
=
True
,
act
=
LinearActivation
())
as
conv
:
conv
+=
proj
conv
+=
proj
...
...
paddle/gserver/tests/img_conv_c.conf
0 → 100644
浏览文件 @
8e6965be
#edit-mode: -*- python -*-
# Copyright (c) 2016 Baidu, Inc. All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from
paddle
.
trainer_config_helpers
import
*
settings
(
batch_size
=
10
)
data
=
data_layer
(
name
=
"input"
,
size
=
8
*
16
*
16
)
conv1
=
img_conv_layer
(
input
=
data
,
filter_size
=
1
,
filter_size_y
=
1
,
num_channels
=
8
,
num_filters
=
16
,
stride
=
1
,
bias_attr
=
False
,
act
=
ReluActivation
(),
layer_type
=
"exconv"
)
conv2
=
img_conv_layer
(
input
=
data
,
filter_size
=
1
,
filter_size_y
=
1
,
num_channels
=
8
,
num_filters
=
16
,
stride
=
1
,
bias_attr
=
False
,
act
=
ReluActivation
(),
layer_type
=
"exconv"
)
concat
=
concat_layer
(
input
=[
conv1
,
conv2
])
conv
=
img_conv_layer
(
input
=
data
,
filter_size
=
1
,
filter_size_y
=
1
,
num_channels
=
8
,
num_filters
=
16
,
stride
=
1
,
bias_attr
=
True
,
act
=
LinearActivation
(),
groups
=
2
,
layer_type
=
"exconv"
)
outputs
(
concat
,
conv
)
paddle/gserver/tests/test_ConvUnify.cpp
0 → 100644
浏览文件 @
8e6965be
/* Copyright (c) 2016 Baidu, Inc. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#include <gtest/gtest.h>
#include <vector>
#include <string>
#include "paddle/gserver/layers/DataLayer.h"
#include "ModelConfig.pb.h"
#include "paddle/trainer/Trainer.h"
#include "paddle/utils/GlobalConstants.h"
#include "paddle/gserver/layers/ExpandConvTransLayer.h"
#include "paddle/math/MathUtils.h"
#include "TestUtil.h"
#include "LayerGradUtil.h"
using
namespace
paddle
;
// NOLINT
using
namespace
std
;
// NOLINT
P_DECLARE_bool
(
use_gpu
);
P_DECLARE_int32
(
gpu_id
);
P_DECLARE_double
(
checkgrad_eps
);
P_DECLARE_bool
(
thread_local_rand_use_global_seed
);
P_DECLARE_bool
(
prev_batch_state
);
// Do one forward pass of convTrans layer and check to see if its output
// matches the given result
MatrixPtr
doOneConvTest
(
size_t
imgSize
,
size_t
output_x
,
size_t
stride
,
size_t
padding
,
size_t
filter_size
,
size_t
channel
,
size_t
numfilters
,
size_t
groups
,
MatrixPtr
&
inputData
,
real
*
param
,
bool
useGpu
)
{
TestConfig
config
;
config
.
biasSize
=
numfilters
;
if
(
useGpu
)
{
config
.
layerConfig
.
set_type
(
"cudnn_conv"
);
}
else
{
config
.
layerConfig
.
set_type
(
"exconv"
);
}
config
.
layerConfig
.
set_num_filters
(
numfilters
);
config
.
layerConfig
.
set_partial_sum
(
1
);
config
.
layerConfig
.
set_shared_biases
(
true
);
size_t
weightSize
=
channel
*
filter_size
*
filter_size
*
config
.
layerConfig
.
num_filters
()
/
groups
;
config
.
inputDefs
.
push_back
({
INPUT_DATA
,
"layer_0"
,
imgSize
*
imgSize
*
channel
,
weightSize
});
LayerInputConfig
*
input
=
config
.
layerConfig
.
add_inputs
();
ConvConfig
*
conv
=
input
->
mutable_conv_conf
();
conv
->
set_filter_size
(
filter_size
);
conv
->
set_filter_size_y
(
filter_size
);
conv
->
set_channels
(
channel
);
conv
->
set_padding
(
padding
);
conv
->
set_padding_y
(
padding
);
conv
->
set_stride
(
stride
);
conv
->
set_stride_y
(
stride
);
conv
->
set_groups
(
groups
);
conv
->
set_filter_channels
(
channel
/
groups
);
conv
->
set_img_size
(
imgSize
);
conv
->
set_output_x
(
output_x
);
config
.
layerConfig
.
set_size
(
conv
->
output_x
()
*
conv
->
output_x
()
*
config
.
layerConfig
.
num_filters
());
config
.
layerConfig
.
set_name
(
"conv"
);
std
::
vector
<
DataLayerPtr
>
dataLayers
;
LayerMap
layerMap
;
vector
<
Argument
>
datas
;
initDataLayer
(
config
,
&
dataLayers
,
&
datas
,
&
layerMap
,
"conv"
,
1
,
false
,
useGpu
);
dataLayers
[
0
]
->
getOutputValue
()
->
zeroMem
();
dataLayers
[
0
]
->
getOutputValue
()
->
copyFrom
(
*
inputData
);
// test layer initialize
std
::
vector
<
ParameterPtr
>
parameters
;
LayerPtr
convLayer
;
initTestLayer
(
config
,
&
layerMap
,
&
parameters
,
&
convLayer
);
convLayer
->
getBiasParameter
()
->
zeroMem
();
convLayer
->
getParameters
()[
0
]
->
zeroMem
();
convLayer
->
getParameters
()[
0
]
->
getBuf
(
PARAMETER_VALUE
)
->
copyFrom
(
param
,
weightSize
);
convLayer
->
forward
(
PASS_GC
);
return
convLayer
->
getOutputValue
();
}
TEST
(
Layer
,
convParaUnified
)
{
#ifndef PADDLE_ONLY_CPU
MatrixPtr
input
,
resultCpu
,
resultGpu
;
input
=
Matrix
::
create
(
1
,
4
*
4
,
false
,
false
);
float
inputData
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
};
float
param
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
9
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
};
input
->
setData
(
inputData
);
resultCpu
=
doOneConvTest
(
/* imgSize */
4
,
/* output_x */
2
,
/* stride */
1
,
/* padding */
0
,
/* filter_size */
3
,
/*channel*/
1
,
/*numfilters*/
2
,
/*groups*/
1
,
input
,
param
,
false
);
resultGpu
=
doOneConvTest
(
/* imgSize */
4
,
/* output_x */
2
,
/* stride */
1
,
/* padding */
0
,
/* filter_size */
3
,
/*channel*/
1
,
/*numfilters*/
2
,
/*groups*/
1
,
input
,
param
,
true
);
checkMatrixEqual
(
resultCpu
,
resultGpu
);
input
=
Matrix
::
create
(
1
,
3
*
3
*
2
,
false
,
false
);
float
inputData2
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
,
17
,
18
};
float
param2
[]
=
{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
8
,
7
,
6
,
5
,
4
,
3
,
2
,
1
};
input
->
setData
(
inputData2
);
resultCpu
=
doOneConvTest
(
/* imgSize */
3
,
/* output_x */
2
,
/* stride */
1
,
/* padding */
0
,
/* filter_size */
2
,
/*channel*/
2
,
/*numfilters*/
2
,
/*groups*/
1
,
input
,
param2
,
false
);
resultGpu
=
doOneConvTest
(
/* imgSize */
3
,
/* output_x */
2
,
/* stride */
1
,
/* padding */
0
,
/* filter_size */
2
,
/*channel*/
2
,
/*numfilters*/
2
,
/*groups*/
1
,
input
,
param2
,
true
);
checkMatrixEqual
(
resultCpu
,
resultGpu
);
float
param3
[]
=
{
1
,
2
,
3
,
4
,
4
,
3
,
2
,
1
};
resultCpu
=
doOneConvTest
(
/* imgSize */
3
,
/* output_x */
2
,
/* stride */
1
,
/* padding */
0
,
/* filter_size */
2
,
/*channel*/
2
,
/*numfilters*/
2
,
/*groups*/
2
,
input
,
param3
,
false
);
resultGpu
=
doOneConvTest
(
/* imgSize */
3
,
/* output_x */
2
,
/* stride */
1
,
/* padding */
0
,
/* filter_size */
2
,
/*channel*/
2
,
/*numfilters*/
2
,
/*groups*/
2
,
input
,
param3
,
true
);
checkMatrixEqual
(
resultCpu
,
resultGpu
);
#endif
}
int
main
(
int
argc
,
char
**
argv
)
{
testing
::
InitGoogleTest
(
&
argc
,
argv
);
initMain
(
argc
,
argv
);
FLAGS_thread_local_rand_use_global_seed
=
true
;
srand
(
1
);
return
RUN_ALL_TESTS
();
}
paddle/gserver/tests/test_LayerGrad.cpp
浏览文件 @
8e6965be
...
@@ -166,9 +166,8 @@ TEST(Projection, scaling) {
...
@@ -166,9 +166,8 @@ TEST(Projection, scaling) {
}
}
}
}
#ifndef PADDLE_ONLY_CPU
void
testProjectionConv
(
size_t
groups
)
{
TEST
(
Projection
,
conv
)
{
const
int
NUM_FILTERS
=
18
;
const
int
NUM_FILTERS
=
16
;
const
int
FILTER_SIZE
=
2
;
const
int
FILTER_SIZE
=
2
;
const
int
FILTER_SIZE_Y
=
3
;
const
int
FILTER_SIZE_Y
=
3
;
const
int
CHANNELS
=
3
;
const
int
CHANNELS
=
3
;
...
@@ -186,7 +185,7 @@ TEST(Projection, conv) {
...
@@ -186,7 +185,7 @@ TEST(Projection, conv) {
conv
->
set_padding_y
(
1
);
conv
->
set_padding_y
(
1
);
conv
->
set_stride
(
2
);
conv
->
set_stride
(
2
);
conv
->
set_stride_y
(
2
);
conv
->
set_stride_y
(
2
);
conv
->
set_groups
(
1
);
conv
->
set_groups
(
groups
);
conv
->
set_filter_channels
(
conv
->
channels
()
/
conv
->
groups
());
conv
->
set_filter_channels
(
conv
->
channels
()
/
conv
->
groups
());
conv
->
set_img_size
(
IMAGE_SIZE
);
conv
->
set_img_size
(
IMAGE_SIZE
);
int
output_x
=
outputSize
(
conv
->
img_size
(),
int
output_x
=
outputSize
(
conv
->
img_size
(),
...
@@ -206,13 +205,20 @@ TEST(Projection, conv) {
...
@@ -206,13 +205,20 @@ TEST(Projection, conv) {
testProjectionGrad
(
testProjectionGrad
(
conf
,
conf
,
INPUT_DATA
,
INPUT_DATA
,
/* parameterSize */
NUM_FILTERS
*
CHANNELS
*
FILTER_SIZE
*
FILTER_SIZE_Y
,
/* parameterSize */
NUM_FILTERS
*
CHANNELS
*
FILTER_SIZE
*
FILTER_SIZE_Y
/
groups
,
/* batchSize */
100
,
/* batchSize */
100
,
true
,
true
,
false
,
false
,
NUM_FILTERS
,
NUM_FILTERS
,
true
);
true
);
}
}
#ifndef PADDLE_ONLY_CPU
TEST
(
Projection
,
conv
)
{
testProjectionConv
(
1
);
testProjectionConv
(
3
);
}
#endif
#endif
TEST
(
Layer
,
BilinearInterpLayer
)
{
TEST
(
Layer
,
BilinearInterpLayer
)
{
...
...
paddle/gserver/tests/test_NetworkCompare.cpp
浏览文件 @
8e6965be
...
@@ -255,6 +255,16 @@ TEST(Compare, img_conv) {
...
@@ -255,6 +255,16 @@ TEST(Compare, img_conv) {
compareNetwork
(
config_file_a
,
config_file_b
);
compareNetwork
(
config_file_a
,
config_file_b
);
FLAGS_use_gpu
=
useGpu
;
FLAGS_use_gpu
=
useGpu
;
}
}
// Test cudnn_conv and exconv give the same result
TEST
(
Compare
,
img_conv2
)
{
std
::
string
config_file_a
=
"./gserver/tests/img_conv_a.conf"
;
std
::
string
config_file_b
=
"./gserver/tests/img_conv_c.conf"
;
bool
useGpu
=
FLAGS_use_gpu
;
FLAGS_use_gpu
=
true
;
compareNetwork
(
config_file_a
,
config_file_b
);
FLAGS_use_gpu
=
useGpu
;
}
#endif
#endif
P_DEFINE_string
(
config_file_a
,
""
,
"config of one network to compare"
);
P_DEFINE_string
(
config_file_a
,
""
,
"config of one network to compare"
);
...
...
python/paddle/trainer/config_parser.py
浏览文件 @
8e6965be
...
@@ -698,7 +698,8 @@ class ConvProjection(Projection):
...
@@ -698,7 +698,8 @@ class ConvProjection(Projection):
ci
=
self
.
proj_conf
.
conv_conf
.
channels
ci
=
self
.
proj_conf
.
conv_conf
.
channels
fh
=
self
.
proj_conf
.
conv_conf
.
filter_size
fh
=
self
.
proj_conf
.
conv_conf
.
filter_size
fw
=
self
.
proj_conf
.
conv_conf
.
filter_size_y
fw
=
self
.
proj_conf
.
conv_conf
.
filter_size_y
return
co
*
ci
*
fh
*
fw
gr
=
self
.
proj_conf
.
conv_conf
.
groups
return
co
*
ci
*
fh
*
fw
/
gr
def
calc_bias_size
(
self
):
def
calc_bias_size
(
self
):
return
self
.
proj_conf
.
num_filters
return
self
.
proj_conf
.
num_filters
...
...
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
8e6965be
...
@@ -129,6 +129,9 @@ class LayerType(object):
...
@@ -129,6 +129,9 @@ class LayerType(object):
HSIGMOID
=
'hsigmoid'
HSIGMOID
=
'hsigmoid'
CONV_LAYER
=
"conv"
CONV_LAYER
=
"conv"
CONVTRANS_LAYER
=
"convt"
CONVTRANS_LAYER
=
"convt"
EXCONV_LAYER
=
"exconv"
EXCONVTRANS_LAYER
=
"exconvt"
CUDNNCONV_LAYER
=
"cudnn_conv"
POOL_LAYER
=
"pool"
POOL_LAYER
=
"pool"
BATCH_NORM_LAYER
=
'batch_norm'
BATCH_NORM_LAYER
=
'batch_norm'
NORM_LAYER
=
'norm'
NORM_LAYER
=
'norm'
...
@@ -1762,7 +1765,8 @@ def img_conv_layer(input,
...
@@ -1762,7 +1765,8 @@ def img_conv_layer(input,
filter_size_y
=
None
,
filter_size_y
=
None
,
stride_y
=
None
,
stride_y
=
None
,
padding_y
=
None
,
padding_y
=
None
,
trans
=
False
):
trans
=
False
,
layer_type
=
None
):
"""
"""
Convolution layer for image. Paddle only support square input currently and
Convolution layer for image. Paddle only support square input currently and
thus input image's width equals height.
thus input image's width equals height.
...
@@ -1829,6 +1833,10 @@ def img_conv_layer(input,
...
@@ -1829,6 +1833,10 @@ def img_conv_layer(input,
:type layer_attr: ExtraLayerAttribute
:type layer_attr: ExtraLayerAttribute
:param trans: true if it is a convTransLayer, false if it is a convLayer
:param trans: true if it is a convTransLayer, false if it is a convLayer
:type trans: bool
:type trans: bool
:param layer_type: specify the layer_type, default is None. If trans=True,
layer_type has to be "exconvt", otherwise layer_type
has to be either "exconv" or "cudnn_conv"
:type layer_type: String
:return: LayerOutput object.
:return: LayerOutput object.
:rtype: LayerOutput
:rtype: LayerOutput
"""
"""
...
@@ -1865,6 +1873,13 @@ def img_conv_layer(input,
...
@@ -1865,6 +1873,13 @@ def img_conv_layer(input,
param_attr
.
attr
[
"initial_strategy"
]
=
0
param_attr
.
attr
[
"initial_strategy"
]
=
0
param_attr
.
attr
[
"initial_smart"
]
=
False
param_attr
.
attr
[
"initial_smart"
]
=
False
if
layer_type
:
if
trans
:
assert
layer_type
in
[
"exconvt"
]
else
:
assert
layer_type
in
[
"exconv"
,
"cudnn_conv"
]
lt
=
layer_type
else
:
lt
=
LayerType
.
CONVTRANS_LAYER
if
trans
else
LayerType
.
CONV_LAYER
lt
=
LayerType
.
CONVTRANS_LAYER
if
trans
else
LayerType
.
CONV_LAYER
l
=
Layer
(
l
=
Layer
(
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录