Skip to content

Commit 3d1f8b4

Browse files
committed
Merge branch 'develop' into doc3
2 parents a36df60 + 9619015 commit 3d1f8b4

File tree

190 files changed

+2205
-3399
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

190 files changed

+2205
-3399
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.gitignore

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ build/
88
.cproject
99
.pydevproject
1010
Makefile
11+
.test_env/

CMakeLists.txt

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
cmake_minimum_required(VERSION 2.8)
22

33
project(paddle CXX C)
4-
set(PADDLE_MAJOR_VERSION 0)
5-
set(PADDLE_MINOR_VERSION 9)
6-
set(PADDLE_PATCH_VERSION 0a0)
7-
set(PADDLE_VERSION ${PADDLE_MAJOR_VERSION}.${PADDLE_MINOR_VERSION}.${PADDLE_PATCH_VERSION})
84

95
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
106
set(PROJ_ROOT ${CMAKE_SOURCE_DIR})
117
include(package)
128
find_package(SWIG 2.0)
139
find_package(CUDA QUIET)
1410
find_package(Protobuf REQUIRED)
11+
12+
# Check protobuf library version.
13+
execute_process(COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --version
14+
OUTPUT_VARIABLE PROTOBUF_VERSION)
15+
string(REPLACE "libprotoc " "" PROTOBUF_VERSION ${PROTOBUF_VERSION})
16+
17+
set(PROTOBUF_3 OFF)
18+
if (${PROTOBUF_VERSION} VERSION_GREATER "3.0.0" OR ${PROTOBUF_VERSION} VERSION_EQUAL "3.0.0")
19+
set(PROTOBUF_3 ON)
20+
endif()
21+
1522
find_package(PythonLibs 2.7 REQUIRED)
1623
find_package(PythonInterp 2.7 REQUIRED)
1724
find_package(ZLIB REQUIRED)
@@ -45,7 +52,7 @@ option(ON_COVERALLS "Generating code coverage data on coveralls or not." OFF)
4552
option(COVERALLS_UPLOAD "Uploading the generated coveralls json." ON)
4653

4754
if(NOT CMAKE_BUILD_TYPE)
48-
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
55+
set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING
4956
"Choose the type of build, options are: Debug Release RelWithDebInfo MinSizeRel"
5057
FORCE)
5158
endif()
@@ -64,31 +71,11 @@ include(check_packages)
6471
include(swig)
6572
include(coveralls)
6673

67-
# add PaddlePaddle version
68-
if(DEFINED ENV{PADDLE_VERSION})
69-
add_definitions(-DPADDLE_VERSION=\"$ENV{PADDLE_VERSION}\")
70-
else()
71-
if(EXISTS ${PROJ_ROOT}/.svn/)
72-
find_package(Subversion REQUIRED)
73-
if(SUBVERSION_FOUND)
74-
Subversion_WC_INFO(${PROJ_ROOT} Project)
75-
add_definitions(-DPADDLE_VERSION=${Project_WC_REVISION})
76-
endif()
77-
elseif(EXISTS ${PROJ_ROOT}/.git/)
78-
find_package(Git REQUIRED)
79-
execute_process(
80-
COMMAND ${GIT_EXECUTABLE} log -1 --format=%H
81-
WORKING_DIRECTORY ${PROJ_ROOT}
82-
OUTPUT_VARIABLE GIT_SHA1
83-
RESULT_VARIABLE GIT_RESULT
84-
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
85-
if(NOT ${GIT_RESULT})
86-
add_definitions(-DPADDLE_VERSION=\"${GIT_SHA1}\")
87-
else()
88-
message(WARNING "Cannot add paddle version from git tag")
89-
endif()
90-
endif()
91-
endif()
74+
# Set PaddlePaddle version to Git tag name or Git commit ID.
75+
find_package(Git REQUIRED)
76+
# version.cmake will get the current PADDLE_VERSION
77+
include(version)
78+
add_definitions(-DPADDLE_VERSION=\"${PADDLE_VERSION}\")
9279

9380

9481
if(NOT WITH_GPU)

RELEASE.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# Release v0.9.0
2+
3+
## New Features:
4+
5+
* New Layers
6+
* bilinear interpolation layer.
7+
* spatial pyramid-pool layer.
8+
* de-convolution layer.
9+
* maxout layer.
10+
* Support rectangle padding, stride, window and input for Pooling Operation.
11+
* Add —job=time in trainer, which can be used to print time info without compiler option -WITH_TIMER=ON.
12+
* Expose cost_weight/nce_layer in `trainer_config_helpers`
13+
* Add FAQ, concepts, h-rnn docs.
14+
* Add Bidi-LSTM and DB-LSTM to quick start demo @alvations
15+
* Add usage track scripts.
16+
17+
## Improvements
18+
19+
* Add Travis-CI for Mac OS X. Enable swig unittest in Travis-CI. Skip Travis-CI when only docs are changed.
20+
* Add code coverage tools.
21+
* Refine convolution layer to speedup and reduce GPU memory.
22+
* Speed up PyDataProvider2
23+
* Add ubuntu deb package build scripts.
24+
* Make Paddle use git-flow branching model.
25+
* PServer support no parameter blocks.
26+
27+
## Bug Fixes
28+
29+
* add zlib link to py_paddle
30+
* add input sparse data check for sparse layer at runtime
31+
* Bug fix for sparse matrix multiplication
32+
* Fix floating-point overflow problem of tanh
33+
* Fix some nvcc compile options
34+
* Fix a bug in yield dictionary in DataProvider
35+
* Fix SRL hang when exit.
36+
37+
# Release v0.8.0beta.1
38+
New features:
39+
40+
* Mac OSX is supported by source code. #138
41+
* Both GPU and CPU versions of PaddlePaddle are supported.
42+
43+
* Support CUDA 8.0
44+
45+
* Enhance `PyDataProvider2`
46+
* Add dictionary yield format. `PyDataProvider2` can yield a dictionary with key is data_layer's name, value is features.
47+
* Add `min_pool_size` to control memory pool in provider.
48+
49+
* Add `deb` install package & docker image for no_avx machines.
50+
* Especially for cloud computing and virtual machines
51+
52+
* Automatically disable `avx` instructions in cmake when machine's CPU don't support `avx` instructions.
53+
54+
* Add Parallel NN api in trainer_config_helpers.
55+
56+
* Add `travis ci` for Github
57+
58+
Bug fixes:
59+
60+
* Several bugs in trainer_config_helpers. Also complete the unittest for trainer_config_helpers
61+
* Check if PaddlePaddle is installed when unittest.
62+
* Fix bugs in GTX series GPU
63+
* Fix bug in MultinomialSampler
64+
65+
Also more documentation was written since last release.
66+
67+
# Release v0.8.0beta.0
68+
69+
PaddlePaddle v0.8.0beta.0 release. The install package is not stable yet and it's a pre-release version.

cmake/version.cmake

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Get the latest git tag.
2+
set(PADDLE_VERSION $ENV{PADDLE_VERSION})
3+
set(tmp_version "HEAD")
4+
while ("${PADDLE_VERSION}" STREQUAL "")
5+
execute_process(
6+
COMMAND ${GIT_EXECUTABLE} describe --tags --abbrev=0 ${tmp_version}
7+
WORKING_DIRECTORY ${PROJ_ROOT}
8+
OUTPUT_VARIABLE GIT_TAG_NAME
9+
RESULT_VARIABLE GIT_RESULT
10+
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
11+
if (NOT ${GIT_RESULT})
12+
# Check the tag is a correct version
13+
if (${GIT_TAG_NAME} MATCHES "v[0-9]+\\.[0-9]+\\.[0-9]+(\\.(a|b|rc)\\.[0-9]+)?")
14+
string(REPLACE "v" "" PADDLE_VERSION ${GIT_TAG_NAME})
15+
else() # otherwise, get the previous git tag name.
16+
set(tmp_version "${GIT_TAG_NAME}~1")
17+
endif()
18+
else()
19+
set(PADDLE_VERSION "0.0.0")
20+
message(WARNING "Cannot add paddle version from git tag")
21+
endif()
22+
endwhile()
23+
24+
message(STATUS "Paddle version is ${PADDLE_VERSION}")

demo/gan/.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
output/
2+
uniform_params/
3+
cifar_params/
4+
mnist_params/
5+
*.png
6+
.pydevproject
7+
.project
8+
*.log
9+
*.pyc
10+
data/mnist_data/
11+
data/cifar-10-batches-py/

demo/gan/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Generative Adversarial Networks (GAN)
2+
3+
This demo implements GAN training described in the original GAN paper (https://arxiv.org/abs/1406.2661) and DCGAN (https://arxiv.org/abs/1511.06434).
4+
5+
The general training procedures are implemented in gan_trainer.py. The neural network configurations are specified in gan_conf.py (for synthetic data) and gan_conf_image.py (for image data).
6+
7+
In order to run the model, first download the corresponding data by running the shell script in ./data.
8+
Then you can run the command below. The flag -d specifies the training data (cifar, mnist or uniform) and flag --useGpu specifies whether to use gpu for training (0 is cpu, 1 is gpu).
9+
10+
$python gan_trainer.py -d cifar --use_gpu 1
11+
12+
The generated images will be stored in ./cifar_samples/
13+
The corresponding models will be stored in ./cifar_params/

demo/gan/data/download_cifar.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2016 Baidu, Inc. All Rights Reserved
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
set -e
15+
wget https://www.cs.toronto.edu/~kriz/cifar-10-python.tar.gz
16+
tar zxf cifar-10-python.tar.gz
17+
rm cifar-10-python.tar.gz
18+

demo/gan/data/get_mnist_data.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env sh
2+
# This script downloads the mnist data and unzips it.
3+
set -e
4+
DIR="$( cd "$(dirname "$0")" ; pwd -P )"
5+
rm -rf "$DIR/mnist_data"
6+
mkdir "$DIR/mnist_data"
7+
cd "$DIR/mnist_data"
8+
9+
echo "Downloading..."
10+
11+
for fname in train-images-idx3-ubyte train-labels-idx1-ubyte t10k-images-idx3-ubyte t10k-labels-idx1-ubyte
12+
do
13+
if [ ! -e $fname ]; then
14+
wget --no-check-certificate http://yann.lecun.com/exdb/mnist/${fname}.gz
15+
gunzip ${fname}.gz
16+
fi
17+
done
18+
19+

demo/gan/gan_conf.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Copyright (c) 2016 Baidu, Inc. All Rights Reserved
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
from paddle.trainer_config_helpers import *
15+
16+
mode = get_config_arg("mode", str, "generator")
17+
assert mode in set(["generator",
18+
"discriminator",
19+
"generator_training",
20+
"discriminator_training"])
21+
22+
is_generator_training = mode == "generator_training"
23+
is_discriminator_training = mode == "discriminator_training"
24+
is_generator = mode == "generator"
25+
is_discriminator = mode == "discriminator"
26+
27+
# The network structure below follows the ref https://arxiv.org/abs/1406.2661
28+
# Here we used two hidden layers and batch_norm
29+
30+
print('mode=%s' % mode)
31+
# the dim of the noise (z) as the input of the generator network
32+
noise_dim = 10
33+
# the dim of the hidden layer
34+
hidden_dim = 10
35+
# the dim of the generated sample
36+
sample_dim = 2
37+
38+
settings(
39+
batch_size=128,
40+
learning_rate=1e-4,
41+
learning_method=AdamOptimizer(beta1=0.5)
42+
)
43+
44+
def discriminator(sample):
45+
"""
46+
discriminator ouputs the probablity of a sample is from generator
47+
or real data.
48+
The output has two dimenstional: dimension 0 is the probablity
49+
of the sample is from generator and dimension 1 is the probabblity
50+
of the sample is from real data.
51+
"""
52+
param_attr = ParamAttr(is_static=is_generator_training)
53+
bias_attr = ParamAttr(is_static=is_generator_training,
54+
initial_mean=1.0,
55+
initial_std=0)
56+
57+
hidden = fc_layer(input=sample, name="dis_hidden", size=hidden_dim,
58+
bias_attr=bias_attr,
59+
param_attr=param_attr,
60+
act=ReluActivation())
61+
62+
hidden2 = fc_layer(input=hidden, name="dis_hidden2", size=hidden_dim,
63+
bias_attr=bias_attr,
64+
param_attr=param_attr,
65+
act=LinearActivation())
66+
67+
hidden_bn = batch_norm_layer(hidden2,
68+
act=ReluActivation(),
69+
name="dis_hidden_bn",
70+
bias_attr=bias_attr,
71+
param_attr=ParamAttr(is_static=is_generator_training,
72+
initial_mean=1.0,
73+
initial_std=0.02),
74+
use_global_stats=False)
75+
76+
return fc_layer(input=hidden_bn, name="dis_prob", size=2,
77+
bias_attr=bias_attr,
78+
param_attr=param_attr,
79+
act=SoftmaxActivation())
80+
81+
def generator(noise):
82+
"""
83+
generator generates a sample given noise
84+
"""
85+
param_attr = ParamAttr(is_static=is_discriminator_training)
86+
bias_attr = ParamAttr(is_static=is_discriminator_training,
87+
initial_mean=1.0,
88+
initial_std=0)
89+
90+
hidden = fc_layer(input=noise,
91+
name="gen_layer_hidden",
92+
size=hidden_dim,
93+
bias_attr=bias_attr,
94+
param_attr=param_attr,
95+
act=ReluActivation())
96+
97+
hidden2 = fc_layer(input=hidden, name="gen_hidden2", size=hidden_dim,
98+
bias_attr=bias_attr,
99+
param_attr=param_attr,
100+
act=LinearActivation())
101+
102+
hidden_bn = batch_norm_layer(hidden2,
103+
act=ReluActivation(),
104+
name="gen_layer_hidden_bn",
105+
bias_attr=bias_attr,
106+
param_attr=ParamAttr(is_static=is_discriminator_training,
107+
initial_mean=1.0,
108+
initial_std=0.02),
109+
use_global_stats=False)
110+
111+
return fc_layer(input=hidden_bn,
112+
name="gen_layer1",
113+
size=sample_dim,
114+
bias_attr=bias_attr,
115+
param_attr=param_attr,
116+
act=LinearActivation())
117+
118+
if is_generator_training:
119+
noise = data_layer(name="noise", size=noise_dim)
120+
sample = generator(noise)
121+
122+
if is_discriminator_training:
123+
sample = data_layer(name="sample", size=sample_dim)
124+
125+
if is_generator_training or is_discriminator_training:
126+
label = data_layer(name="label", size=1)
127+
prob = discriminator(sample)
128+
cost = cross_entropy(input=prob, label=label)
129+
classification_error_evaluator(input=prob, label=label, name=mode+'_error')
130+
outputs(cost)
131+
132+
if is_generator:
133+
noise = data_layer(name="noise", size=noise_dim)
134+
outputs(generator(noise))

0 commit comments

Comments
 (0)