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

fix quick start for fluid #9660 #9820

Merged
merged 9 commits into from
Apr 24, 2018

Conversation

seiriosPlus
Copy link
Collaborator

fix quick start for fluid #9660

@jacquesqiao
Copy link
Member

ref:`install_steps`

The format of this line seems not right.

@jacquesqiao
Copy link
Member

jacquesqiao commented Apr 11, 2018

Have you tested the process in this doc? @seiriosPlus This is the first demo user will see, so we must ensure it can run properly.

@shanyi15
Copy link
Collaborator

shanyi15 commented Apr 11, 2018

ref:install_steps The format of this line seems not right.

I read the corresponding v2 doc in https://github.com/PaddlePaddle/Paddle/blob/develop/doc/v2/getstarted/quickstart_en.rst

and find the same

ref:install_steps

maybe it is a .rst grammar? I'm not sure.

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

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

目前的代码量太多,超过100行了。快速开始里的代码(包括注释和空行,一共19行),是为了让用户安装完后,快速验证安装的版本是否正确,能否执行出正确的内容,所以代码量要控制。

这部分代码会放在首页:http://www.paddlepaddle.org/ ,因此比较重要。

当时V2版本为了达到这一目的,删掉了train部分,因为这部分的代码量相对较多。因此fluid版本中,也可以只保留inference部分。同时inference中的代码,也进行简化:

  • 能合并的部分尽量合并,比如
inference_scope = fluid.core.Scope()
with fluid.scope_guard(inference_scope):

能合并成一行:

with fluid.scope_guard(fluid.core.Scope())
  • 注释部分尽量精简,不用写很多
  • train训练完的模型可以像V2一样,保存在某一个地方。
  • main函数可以删掉。

@shanyi15 代码完善后,可以请 @jetfuel 帮忙放到首页上么?

@shanyi15
Copy link
Collaborator

收到

@seiriosPlus
Copy link
Collaborator Author

@luotao1 收到, 这块代码我跟 @jacquesqiao 龙飞老师讨论了以后, 计划将训练后的模型部分放在paddle dataset中, 快速开始中只保留infer 和 模型定义的代码

@seiriosPlus
Copy link
Collaborator Author

@jacquesqiao @luotao1 @shanyi15

  1. 代码已重新优化
  2. ref:install_steps 是历史遗留问题,我参考教程做了一下优化

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

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

  1. 目前代码有27行,我有一个更简单的版本(15行)供大家参考:
import paddle.fluid as fluid
import numpy

with fluid.scope_guard(fluid.core.Scope()):
    exe = fluid.Executor(fluid.CPUPlace())
    
    [inference_program, feed_target_names,fetch_targets] = 
        fluid.io.load_inference_model(paddle.dataset.uci_housing.fluid_model(), exe)

    tensor_x = numpy.random.uniform(0, 10,[10, 13]).astype("float32")
    result = exe.run(inference_program,
                     feed={feed_target_names[0]: tensor_x},
                     fetch_list=fetch_targets)

    print("infer results: ", result[0])

paddle.dataset.uci_housing.fluid_model()用训练好的模型测试后,打印结果为

('infer results: ', array([[-20.94965  ],
       [-22.025486 ],
       [-17.864204 ],
       [ -9.126383 ],
       [ -4.4889793],
       [-16.532032 ],
       [ -3.5934944],
       [-19.41196  ],
       [-22.91457  ],
       [ -7.709648 ]], dtype=float32))
  1. 27行的 .. code-block:: python和28行中间要空一行,不然显示不出代码,https://github.com/seiriosPlus/Paddle/blob/d13ca96781d17bcf99b0ae443a433bcd72812381/doc/fluid/getstarted/quickstart_cn.rst
  2. 最终的代码里面需要加一些简单注释
  3. 不能把路径写死,还是要采用原来的方式。ref:install_steps有什么问题么

@seiriosPlus
Copy link
Collaborator Author

seiriosPlus commented Apr 12, 2018

@luotao1
用随机数测试的话,结果会出现很多负数,感觉结果不是很真实
最后一行的print, 因为咱们的嵌套数据结构,直接print的话,输出的格式不太友好
ref:install_steps 这个我还是改回去吧,rst我不太懂.
我再加一下必要的注释

@luotao1
Copy link
Contributor

luotao1 commented Apr 12, 2018

用随机数测试的话,结果会出现很多负数,感觉结果不是很真实
最后一行的print, 因为咱们的嵌套数据结构,直接print的话,输出的格式不太友好

同意采用真实数。

  1. 能否只取一个真实数呢?这样就可以省去几个for循环了。
  2. 能否将这个真实数封装一下呢?这样获取后的格式类似tensor_x,就不需要x = fluid.layers.data(name='x', shape=[13], dtype='float32')这行了。

@seiriosPlus
Copy link
Collaborator Author

@luotao1 代码已重新优化

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

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

LGTM for the quick start codes.

URL_MODEL = 'https://github.com/PaddlePaddle/book/raw/develop/01.fit_a_line/fit_a_line.tar'
MD5_MODEL = '52fc3da8ef3937822fcdd87ee05c0c9b'

FLUID_URL_MODEL = 'https://github.com/PaddlePaddle/book/raw/develop/01.fit_a_line/fluid/fit_a_line.fluid.tar'
Copy link
Contributor

Choose a reason for hiding this comment

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

原来的路径是V2的路径。现在python/paddle/datasetpython/paddle/v2/dataset一样,如果修改一部分的话,会导致后面两者不太一样。是不是把其中的一个变成另一个的软连接比较好? @helinwang @dzhwinter @JiayiFeng @jacquesqiao

Copy link
Contributor

Choose a reason for hiding this comment

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

我试过alias,alias的paddle.v2.dataset package: from paddle.dataset import *
Python里写import paddle.v2.dataset是没有问题,但是import paddle.v2.dataset.mnist会报错。所以就没有用alias。
如果有Python解决方法那就最好了。

如果无法解决,我觉得我们deprecate paddle.v2.dataset(不再更新),只更新paddle.dataset也是可以。

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

赞同 @helinwang , 如果后续专注于fluid及后续版本的开发,将v2进行独立是一个可行的方案

@seiriosPlus
Copy link
Collaborator Author

我把v2下的dataset删除了,把v2中的代码合并到了paddle.dataset中 @shanyi15 @luotao1 @helinwang

@luotao1
Copy link
Contributor

luotao1 commented Apr 23, 2018

我把v2下的dataset删除了,把v2中的代码合并到了paddle.dataset中

请问这部分能做为一个单独的PR提么?

Copy link
Contributor

@luotao1 luotao1 left a comment

Choose a reason for hiding this comment

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

LGTM! 关于v2 dataset的,可以再下一个PR中修改

@seiriosPlus seiriosPlus merged commit d67b9ce into PaddlePaddle:develop Apr 24, 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.

5 participants