提交 12cac800 编写于 作者: Q qiaolongfei

clean topology.py

上级 909bd269
......@@ -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()
......@@ -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()
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册