From 2715e9de6fb656693843bb4dd254eaedb587ad94 Mon Sep 17 00:00:00 2001 From: Luo Tao Date: Thu, 23 Feb 2017 13:14:32 +0800 Subject: [PATCH] add ParamAttr in V2 --- python/paddle/v2/__init__.py | 3 ++- python/paddle/v2/attr.py | 23 +++++++++++++++++++++++ python/paddle/v2/layer.py | 9 +++++++-- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 python/paddle/v2/attr.py diff --git a/python/paddle/v2/__init__.py b/python/paddle/v2/__init__.py index 30d0b2a398..0cf7b8e903 100644 --- a/python/paddle/v2/__init__.py +++ b/python/paddle/v2/__init__.py @@ -18,11 +18,12 @@ import parameters import trainer import event import data_type +import attr import py_paddle.swig_paddle as api __all__ = [ 'optimizer', 'layer', 'activation', 'parameters', 'init', 'trainer', - 'event', 'data_type' + 'event', 'data_type', 'attr' ] diff --git a/python/paddle/v2/attr.py b/python/paddle/v2/attr.py new file mode 100644 index 0000000000..40c64f621b --- /dev/null +++ b/python/paddle/v2/attr.py @@ -0,0 +1,23 @@ +# Copyright (c) 2016 PaddlePaddle Authors. 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.attrs import * + +__all__ = [ + "Param", + "Extra", +] + +Param = ParameterAttribute +Extra = ExtraLayerAttribute diff --git a/python/paddle/v2/layer.py b/python/paddle/v2/layer.py index cd6dd5110a..3920d4a08f 100644 --- a/python/paddle/v2/layer.py +++ b/python/paddle/v2/layer.py @@ -74,6 +74,8 @@ from paddle.trainer_config_helpers.config_parser_utils import \ from paddle.trainer_config_helpers.default_decorators import wrap_name_default import data_type +import activation +import attr __all__ = [ 'parse_network', 'data', 'fc', 'max_id', 'classification_cost', @@ -230,8 +232,11 @@ if __name__ == '__main__': weight = data(name='weight', type=data_type.dense_vector(10)) score = data(name='score', type=data_type.dense_vector(1)) - hidden = fc(input=pixel, size=100, act=conf_helps.SigmoidActivation()) - inference = fc(input=hidden, size=10, act=conf_helps.SoftmaxActivation()) + hidden = fc(input=pixel, + size=100, + act=activation.Sigmoid(), + param_attr=attr.Param(name='hidden')) + inference = fc(input=hidden, size=10, act=activation.Softmax()) maxid = max_id(input=inference) cost1 = classification_cost(input=inference, label=label) cost2 = classification_cost(input=inference, label=label, weight=weight) -- GitLab