Skip to content
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

使用FLuid版本,之前定义的神经网络还可以直接使用吗? #8888

Closed
yeyupiaoling opened this issue Mar 8, 2018 · 7 comments
Assignees
Labels
User 用于标记用户问题

Comments

@yeyupiaoling
Copy link
Contributor

比如我们之前定义的网络是这样的https://github.com/PaddlePaddle/models/blob/develop/image_classification/vgg.py#L6-L38

如果使用FLuid版本,需要修改神经网络吗?

@ranqiu92 ranqiu92 added the User 用于标记用户问题 label Mar 8, 2018
@ranqiu92
Copy link
Contributor

ranqiu92 commented Mar 8, 2018

需要修改。

@yeyupiaoling
Copy link
Contributor Author

要怎么修改呢?如果只是修改data,那不算

image = fluid.layers.data(name='image', shape=image_shape, dtype='float32')

@ranqiu92
Copy link
Contributor

ranqiu92 commented Mar 8, 2018

所有的layer都在fluid下了 而不是 paddle下,可以去参考 https://github.com/PaddlePaddle/models/tree/develop/fluid 下的例子

@yeyupiaoling
Copy link
Contributor Author

@ranqiu92
它们的参数相同吗?比如我想把这例子的mobilenet换成vgg

比如把

paddle.networks.img_conv_group

换成

fluid.layers.conv2d

paddle.layer.fc

换成

fluid.layers.fc

@wangkuiyi
Copy link
Collaborator

wangkuiyi commented Mar 9, 2018

@yeyupiaoling 的问题核心是不是Paddle 1程序如何迁移到PaddlePaddle Fluid?我理解这是一个挺重要的问题。我是Fluid的设计者,但是我对Paddle 1的API不够熟悉,所以不能简单扼要的回答。请 @qingqing01 或者 @reyoung 方便的时候看看吧。 这二位对 Paddle 1 很熟悉,并且参与了 Fluid 的开发工作,对两方面都熟悉。

@qingqing01
Copy link
Contributor

qingqing01 commented Mar 9, 2018

@yeyupiaoling 关于Paddle 1和Fluid的API层面的区别:

可以对比 https://github.com/PaddlePaddle/book/blob/develop/03.image_classification/vgg.pyhttps://github.com/dzhwinter/benchmark/blob/master/fluid/vgg16.py

  1. 网络定义上类似,如下。迁移过程注意,要Fluid layer名字是否相同、参数顺序。Fluid API文档参考:http://www.paddlepaddle.org/docs/develop/api/en/fluid/layers.html

    例如: Paddle 1:

    def vgg_bn_drop(input):
      def conv_block(ipt, num_filter, groups, dropouts, num_channels=None):
          return paddle.networks.img_conv_group(
            input=ipt,
            num_channels=num_channels,
            pool_size=2,
            pool_stride=2,
            conv_num_filter=[num_filter] * groups,
            conv_filter_size=3,
            conv_act=paddle.activation.Relu(),
            conv_with_batchnorm=True,
            conv_batchnorm_drop_rate=dropouts,
            pool_type=paddle.pooling.Max())
        # ...

    Fluid:

    def vgg16_bn_drop(input):
       def conv_block(input, num_filter, groups, dropouts):
         return fluid.nets.img_conv_group(
            input=input,
            pool_size=2,
            pool_stride=2,
            conv_num_filter=[num_filter] * groups,
            conv_filter_size=3,
            conv_act='relu',
            conv_with_batchnorm=True,
            conv_batchnorm_drop_rate=dropouts,
            pool_type='max')
      # ...
  2. Optimizer使用有所不同,请对比:https://github.com/PaddlePaddle/book/blob/develop/03.image_classification/train.py#L52https://github.com/dzhwinter/benchmark/blob/master/fluid/vgg16.py#L104

    Paddle 1:

       momentum_optimizer = paddle.optimizer.Momentum(
        momentum=0.9,
        regularization=paddle.optimizer.L2Regularization(rate=0.0002 * 128),
        learning_rate=0.1 / 128.0,
        learning_rate_decay_a=0.1,
        learning_rate_decay_b=50000 * 100,
        learning_rate_schedule='discexp')

    Fluid:

    optimizer = fluid.optimizer.Momentum(
        learning_rate=fluid.layers.exponential_decay(
            learning_rate=learning_rate,
            decay_steps=40000,
            decay_rate=0.1,
            staircase=True),
        momentum=0.9,
        regularization=fluid.regularizer.L2Decay(0.0005), )
    opts = optimizer.minimize(loss)
  3. 执行过程有所不同,Paddle 1用 trainer.train(...), Fluid用fluid.Executor(place).Run(...)。请仔细对比上述链接。

  4. 输出loss和accuracy获取也不同。请仔细对比上述链接。

  5. 模型保存等等都有所不同,请仔细对比上述链接。
    另外,Fluid的文档也在持续完善中,有任何问题,欢迎继续讨论。

@yeyupiaoling
Copy link
Contributor Author

@wangkuiyi @qingqing01
谢谢您们的回答,非常感谢青青姐的详细回答,答得很具体。也期待Fluid有更好的文档

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
User 用于标记用户问题
Projects
None yet
Development

No branches or pull requests

5 participants