diff --git a/python/paddle/v2/__init__.py b/python/paddle/v2/__init__.py index 30d0b2a398bd0e39895daf9b1421ec736ab8da83..0cf7b8e9039f7393ae9fcf73faeeeb8fbf11df31 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 0000000000000000000000000000000000000000..40c64f621b443d5613468b27d030ab08776641b2 --- /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 cd6dd5110a44b2bb9f5bf3f0a0d789ec9a2290fc..3920d4a08fc6271816d35bbb234e47ab3b93d3c9 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)