Skip to content

change network config in mnist/api_trian.py to v2#3

Merged
reyoung merged 2 commits intoreyoung:feature/python.paddle.v2from
jacquesqiao:v2
Jan 17, 2017
Merged

change network config in mnist/api_trian.py to v2#3
reyoung merged 2 commits intoreyoung:feature/python.paddle.v2from
jacquesqiao:v2

Conversation

@jacquesqiao
Copy link
Collaborator

No description provided.

name='label', size=10))
# Create Simple Gradient Machine.
model_config = paddle.config.parse_network(network_config)
model_config = paddle.layers.parse_network(cost)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里我有几个问题。

  1. 把cost写在网络里,作为一个layer —— 这个的前提是不是我们可以操作网络中任何一层?因为我们训练好网路之后,做Inference的时候,是不需要这个cost layer的,只需要它之前的那些layers。如果真是如此,我们的Inference code应该怎么写呢?

  2. 有的网络是一个输入,多组输出。比如一个网路的输入是摄像头拍的图像,一个输出是“图中有没有红绿灯”,另一个输出是“图中有没有限速标志”,第三个输出是“图中有没有横穿马路的行人”。这样的网络是不是会有三个costs?那么其中哪一个cost可以用来指代网络呢?

Copy link
Collaborator Author

@jacquesqiao jacquesqiao Jan 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把cost写在网络里,作为一个layer —— 这个的前提是不是我们可以操作网络中任何一层?因为我们训练好网路之后,做Inference的时候,是不需要这个cost layer的,只需要它之前的那些layers。如果真是如此,我们的Inference code应该怎么写呢?

对的,任意一层都可以直接使用,现在可以这么写:
paddle.layers.parse_network(inference)

有的网络是一个输入,多组输出。比如一个网路的输入是摄像头拍的图像,一个输出是“图中有没有红绿灯”,另一个输出是“图中有没有限速标志”,第三个输出是“图中有没有横穿马路的行人”。这样的网络是不是会有三个costs?那么其中哪一个cost可以用来指代网络呢?

每个被parse_network parse的layer(可能是cost)可以表达和自己关联的所有layer,他们之间可能有共享的部分。
paddle.layers.parse_network(layer1, layer2)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在现在的模式中cost只是普通layer的一种,没什么特殊的,传给parse_network的自动成为output layer。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

没看明白。

  1. paddle.layers.parse_network(inference) 里的 inference 是什么?

  2. paddle.layers.parse_network(layer1, layer2) 里的 layer1layer2是什么关系?

Copy link
Collaborator Author

@jacquesqiao jacquesqiao Jan 17, 2017

Choose a reason for hiding this comment

The 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,他们彼此是有连接关系的。

  1. 在训练的时候,需要用到cost,所以创建model的时候传入cost这一层,paddle.layers.parse_network(cost) 就可以构造一个计算cost所需要的完整的network。

  2. 预测的时候,无需cost层,只需要cost上一层(这里叫做inference),
    paddle.layers.parse_network(inference) 就可以构造一个计算inference所需要的完整的network。

  3. layer1layer2本身所代表的网络结构,在他们定义的时候已经确定好了,传给 parse_network 的时候,会在parse出来的model中被标记为output,然后在forward的时候,他们的输出的作为output。

Copy link

@wangkuiyi wangkuiyi Jan 17, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这下看懂了。谢谢!这样说来,我们考虑的基本是一致的。

有几个小问题:

  1. 这里的命名可以简化:paddle.layers.data_layer ==> paddle.layer.data

  2. 构建网络的时候,我们需要protobuf吗?从这个例子里看,paddle.layer.fc返回的是一个Layer类型的对象,它里面保存了其输入layers,比如imgs。所以通过traverse这个数据结构,我们就可以visualize这个网络。看上去没有protobuf什么事儿了。

  3. 如果没有protobuf,那么 parse_network这个函数的名字貌似就不需要了。

  4. 之前徐老师提醒:network和parameter两个概念都要暴露给用户,因为有些网络部分用的是同样的parameters。比如一个计算两个向量距离的网络,对于每个输入向量都要用同样的方法投影到一个latent space,然后比较两个投影之间的cosine distance。在这个例子里,两个向量对应的两个投影layer要使用同样的一组参数。不知道这个情况考虑到了没有?

  5. GAN以及其他类型的网络,需要能把两个网络拼接在一起。不知道这个考虑到了没有?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1、Protobuf是Paddle C++那边需要的数据类型。
2&3、parse_network这个函数可以没有。因为最后会把Layer传到一个Model里面。
4、可以share parameters
5、目前还没考虑拼接怎么搞。。先一步一步来吧。

@reyoung reyoung merged commit d896ff4 into reyoung:feature/python.paddle.v2 Jan 17, 2017
Copy link

@Zrachel Zrachel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

两点疑问

model_average=paddle.optimizer.ModelAverage(average_window=0.5),
regularization=paddle.optimizer.L2Regularization(rate=0.5))

# define network
Copy link

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,有地方定义吗?

name='label', size=10))
# Create Simple Gradient Machine.
model_config = paddle.config.parse_network(network_config)
model_config = paddle.layers.parse_network(cost)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感觉parse_network(cost)这个函数的名字没有tf里optimizer = tf.train.GradientDescentOptimizer(1.0).minimize(loss)这个名字容易看懂。。。

reyoung pushed a commit that referenced this pull request Aug 9, 2017
reyoung pushed a commit that referenced this pull request Oct 23, 2017
reyoung pushed a commit that referenced this pull request Feb 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants