From 12cac800acf29c39c717e03f934abe35ad5ab0e7 Mon Sep 17 00:00:00 2001 From: qiaolongfei Date: Fri, 24 Feb 2017 10:13:53 +0800 Subject: [PATCH] clean topology.py --- python/paddle/v2/tests/topology_test.py | 37 ++++++++++++------------- python/paddle/v2/topology.py | 24 +--------------- 2 files changed, 19 insertions(+), 42 deletions(-) diff --git a/python/paddle/v2/tests/topology_test.py b/python/paddle/v2/tests/topology_test.py index 7360ed8f7b2..be60a577bea 100644 --- a/python/paddle/v2/tests/topology_test.py +++ b/python/paddle/v2/tests/topology_test.py @@ -19,25 +19,6 @@ import paddle.trainer_config_helpers as conf_helps class TestTopology(unittest.TestCase): - def test_parse(self): - pixel = layer.data(name='pixel', type=data_type.dense_vector(784)) - label = layer.data(name='label', type=data_type.integer_value(10)) - hidden = layer.fc(input=pixel, - size=100, - act=conf_helps.SigmoidActivation()) - inference = layer.fc(input=hidden, - size=10, - act=conf_helps.SoftmaxActivation()) - maxid = layer.max_id(input=inference) - cost1 = layer.classification_cost(input=inference, label=label) - cost2 = layer.cross_entropy_cost(input=inference, label=label) - - print topology.Topology(cost2).proto() - print topology.Topology([cost1]).proto() - print topology.Topology([cost1, cost2]).proto() - print topology.Topology(cost2).proto() - print topology.Topology([inference, maxid]).proto() - def test_data_type(self): pixel = layer.data(name='pixel', type=data_type.dense_vector(784)) label = layer.data(name='label', type=data_type.integer_value(10)) @@ -74,6 +55,24 @@ class TestTopology(unittest.TestCase): self.assertEqual(pixel_layer, pixel) self.assertEqual(label_layer, label) + def test_parse(self): + pixel = layer.data(name='pixel', type=data_type.dense_vector(784)) + label = layer.data(name='label', type=data_type.integer_value(10)) + hidden = layer.fc(input=pixel, + size=100, + act=conf_helps.SigmoidActivation()) + inference = layer.fc(input=hidden, + size=10, + act=conf_helps.SoftmaxActivation()) + maxid = layer.max_id(input=inference) + cost1 = layer.classification_cost(input=inference, label=label) + cost2 = layer.cross_entropy_cost(input=inference, label=label) + + topology.Topology(cost2).proto() + topology.Topology([cost1]).proto() + topology.Topology([cost1, cost2]).proto() + topology.Topology([inference, maxid]).proto() + if __name__ == '__main__': unittest.main() diff --git a/python/paddle/v2/topology.py b/python/paddle/v2/topology.py index 28cc8892e15..20fa891d656 100644 --- a/python/paddle/v2/topology.py +++ b/python/paddle/v2/topology.py @@ -14,10 +14,8 @@ import collections -import paddle.trainer_config_helpers as conf_helps from paddle.proto.ModelConfig_pb2 import ModelConfig -import data_type import layer as v2_layer __all__ = ['Topology'] @@ -62,7 +60,7 @@ class Topology(object): return result_layer[0] - def get_data_layer(self): + def data_layer(self): """ get all data layer :return: @@ -101,23 +99,3 @@ class Topology(object): def __check_layer_type__(layer): if not isinstance(layer, v2_layer.LayerV2): raise ValueError('layer should have type paddle.layer.Layer') - - -if __name__ == '__main__': - pixel = v2_layer.data(name='pixel', type=data_type.dense_vector(784)) - label = v2_layer.data(name='label', type=data_type.integer_value(10)) - hidden = v2_layer.fc(input=pixel, - size=100, - act=conf_helps.SigmoidActivation()) - inference = v2_layer.fc(input=hidden, - size=10, - act=conf_helps.SoftmaxActivation()) - maxid = v2_layer.max_id(input=inference) - cost1 = v2_layer.classification_cost(input=inference, label=label) - cost2 = v2_layer.cross_entropy_cost(input=inference, label=label) - - print Topology(cost2).proto() - print Topology([cost1]).proto() - print Topology([cost1, cost2]).proto() - print Topology(cost2).proto() - print Topology([inference, maxid]).proto() -- GitLab