-
Notifications
You must be signed in to change notification settings - Fork 0
change network config in mnist/api_trian.py to v2 #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,18 +13,6 @@ | |
| from mnist_util import read_from_mnist | ||
|
|
||
|
|
||
| def network_config(): | ||
| imgs = paddle.config.data_layer(name='pixel', size=784) | ||
| hidden1 = paddle.config.fc_layer(input=imgs, size=200) | ||
| hidden2 = paddle.config.fc_layer(input=hidden1, size=200) | ||
| inference = paddle.config.fc_layer( | ||
| input=hidden2, size=10, act=paddle.config.SoftmaxActivation()) | ||
| cost = paddle.config.classification_cost( | ||
| input=inference, label=paddle.config.data_layer( | ||
| name='label', size=10)) | ||
| paddle.config.outputs(cost) | ||
|
|
||
|
|
||
| def generator_to_batch(generator, batch_size): | ||
| ret_val = list() | ||
| for each_item in generator: | ||
|
|
@@ -67,8 +55,17 @@ def main(): | |
| model_average=paddle.optimizer.ModelAverage(average_window=0.5), | ||
| regularization=paddle.optimizer.L2Regularization(rate=0.5)) | ||
|
|
||
| # define network | ||
| imgs = paddle.layers.data_layer(name='pixel', size=784) | ||
| hidden1 = paddle.layers.fc_layer(input=imgs, size=200) | ||
| hidden2 = paddle.layers.fc_layer(input=hidden1, size=200) | ||
| inference = paddle.layers.fc_layer( | ||
| input=hidden2, size=10, act=paddle.config.SoftmaxActivation()) | ||
| cost = paddle.layers.classification_cost( | ||
| input=inference, label=paddle.layers.data_layer( | ||
| name='label', size=10)) | ||
| # Create Simple Gradient Machine. | ||
| model_config = paddle.config.parse_network(network_config) | ||
| model_config = paddle.layers.parse_network(cost) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里我有几个问题。
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
对的,任意一层都可以直接使用,现在可以这么写:
每个被parse_network parse的layer(可能是cost)可以表达和自己关联的所有layer,他们之间可能有共享的部分。
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 在现在的模式中cost只是普通layer的一种,没什么特殊的,传给parse_network的自动成为output layer。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 没看明白。
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. imgs = paddle.layers.data_layer(name='pixel', size=784)
hidden1 = paddle.layers.fc_layer(input=imgs, size=200)
hidden2 = paddle.layers.fc_layer(input=hidden1, size=200)
inference = paddle.layers.fc_layer(input=hidden2, size=10, act=paddle.config.SoftmaxActivation())
cost = paddle.layers.classification_cost(input=inference, label=paddle.layers.data_layer(name='label', size=10))不好意思,应该把上下文说清楚。上面这段代码,定义了很多个layer,他们彼此是有连接关系的。
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这下看懂了。谢谢!这样说来,我们考虑的基本是一致的。 有几个小问题:
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1、Protobuf是Paddle C++那边需要的数据类型。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 感觉 |
||
| m = paddle.raw.GradientMachine.createFromConfigProto( | ||
| model_config, paddle.raw.CREATE_MODE_NORMAL, optimizer.enable_types()) | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不理解为什么选择将network拿出来了呢?因为有的网络config很长,有的网络还要自己定义一个子模块的函数,所以放在一个network函数里是不是更好?不然有点乱。。。
另外,没找到batch_size,有地方定义吗?