From 83abbce8eb750f7e7c844b0959851e901806aa91 Mon Sep 17 00:00:00 2001 From: guosheng Date: Mon, 21 Aug 2017 14:05:56 +0800 Subject: [PATCH] Follow comments and refine ScaleShiftLayer --- paddle/gserver/layers/ScaleShiftLayer.cpp | 5 +++-- paddle/gserver/tests/test_LayerGrad.cpp | 4 ++-- python/paddle/trainer_config_helpers/layers.py | 5 +++-- .../protostr/test_scale_shift_layer.protostr | 14 +++++++------- .../tests/configs/test_scale_shift_layer.py | 6 ++---- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/paddle/gserver/layers/ScaleShiftLayer.cpp b/paddle/gserver/layers/ScaleShiftLayer.cpp index 4f5b1c6225a..06dcb409f8c 100644 --- a/paddle/gserver/layers/ScaleShiftLayer.cpp +++ b/paddle/gserver/layers/ScaleShiftLayer.cpp @@ -17,8 +17,9 @@ limitations under the License. */ namespace paddle { /** - * A layer does scaling and shifting to the input by appling a slope and - * an intercept which are trainable to the input element-wise. + * A layer applies a slope and an intercept to the input element-wise for + * scaling and shifting. Noting that this layer is trainable which differs + * from the SlopeInterceptLayer. * * \f[ * y = wx + b diff --git a/paddle/gserver/tests/test_LayerGrad.cpp b/paddle/gserver/tests/test_LayerGrad.cpp index 65429ebada1..dd2c955e6a4 100644 --- a/paddle/gserver/tests/test_LayerGrad.cpp +++ b/paddle/gserver/tests/test_LayerGrad.cpp @@ -2008,8 +2008,8 @@ TEST(Layer, RowL2NormLayer) { } TEST(Layer, ScaleShiftLayer) { - const size_t batchSize = 128; - const size_t size = 512; + const size_t batchSize = 16; + const size_t size = 32; TestConfig config; config.layerConfig.set_type("scale_shift"); config.layerConfig.set_size(size); diff --git a/python/paddle/trainer_config_helpers/layers.py b/python/paddle/trainer_config_helpers/layers.py index 4c7217024ab..ec3a87aa366 100755 --- a/python/paddle/trainer_config_helpers/layers.py +++ b/python/paddle/trainer_config_helpers/layers.py @@ -6219,8 +6219,9 @@ def kmax_sequence_score_layer(input, name=None, beam_size=1): @wrap_bias_attr_default() def scale_shift_layer(input, name=None, param_attr=None, bias_attr=None): """ - A layer does scaling and shifting to the input by appling a slope and - an intercept which are trainable to the input element-wise. + A layer applies a slope and an intercept to the input element-wise for + scaling and shifting. Noting that this layer is trainable which differs + from the slope_intercept_layer. .. math:: y = w * x + b diff --git a/python/paddle/trainer_config_helpers/tests/configs/protostr/test_scale_shift_layer.protostr b/python/paddle/trainer_config_helpers/tests/configs/protostr/test_scale_shift_layer.protostr index efaf20f8a76..35ade126a25 100644 --- a/python/paddle/trainer_config_helpers/tests/configs/protostr/test_scale_shift_layer.protostr +++ b/python/paddle/trainer_config_helpers/tests/configs/protostr/test_scale_shift_layer.protostr @@ -14,7 +14,6 @@ layers { input_layer_name: "data" input_parameter_name: "___scale_shift_0__.w0" } - bias_parameter_name: "___scale_shift_0__.wbias" } layers { name: "__scale_shift_1__" @@ -25,6 +24,7 @@ layers { input_layer_name: "data" input_parameter_name: "___scale_shift_1__.w0" } + bias_parameter_name: "___scale_shift_1__.wbias" } parameters { name: "___scale_shift_0__.w0" @@ -37,24 +37,24 @@ parameters { initial_smart: true } parameters { - name: "___scale_shift_0__.wbias" + name: "___scale_shift_1__.w0" size: 1 initial_mean: 0.0 - initial_std: 0.0 + initial_std: 1.0 dims: 1 dims: 1 initial_strategy: 0 - initial_smart: false + initial_smart: true } parameters { - name: "___scale_shift_1__.w0" + name: "___scale_shift_1__.wbias" size: 1 initial_mean: 0.0 - initial_std: 1.0 + initial_std: 0.0 dims: 1 dims: 1 initial_strategy: 0 - initial_smart: true + initial_smart: false } input_layer_names: "data" output_layer_names: "__scale_shift_0__" diff --git a/python/paddle/trainer_config_helpers/tests/configs/test_scale_shift_layer.py b/python/paddle/trainer_config_helpers/tests/configs/test_scale_shift_layer.py index 818d71f15db..dd589116fa9 100644 --- a/python/paddle/trainer_config_helpers/tests/configs/test_scale_shift_layer.py +++ b/python/paddle/trainer_config_helpers/tests/configs/test_scale_shift_layer.py @@ -1,11 +1,9 @@ from paddle.trainer_config_helpers import * -settings(batch_size=1000, learning_rate=1e-5) - data = data_layer(name='data', size=100) -scale = scale_shift_layer(input=data) +scale = scale_shift_layer(input=data, bias_attr=False) -scale_shift = scale_shift_layer(input=data, bias_attr=False) +scale_shift = scale_shift_layer(input=data) outputs(scale, scale_shift) -- GitLab