Skip to content

Commit d67b9ce

Browse files
authored
Merge pull request #9820 from seiriosPlus/quick_help
fix quick start for fluid #9660
2 parents dd59465 + 6e8510f commit d67b9ce

File tree

3 files changed

+124
-4
lines changed

3 files changed

+124
-4
lines changed

doc/fluid/getstarted/quickstart_cn.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
快速开始
2+
========
3+
4+
快速安装
5+
--------
6+
7+
PaddlePaddle支持使用pip快速安装,目前支持CentOS 6以上, Ubuntu 14.04以及MacOS 10.12,并安装有Python2.7。
8+
执行下面的命令完成快速安装,版本为cpu_avx_openblas:
9+
10+
.. code-block:: bash
11+
12+
pip install paddlepaddle
13+
14+
如果需要安装支持GPU的版本(cuda7.5_cudnn5_avx_openblas),需要执行:
15+
16+
.. code-block:: bash
17+
18+
pip install paddlepaddle-gpu
19+
20+
更详细的安装和编译方法参考: :ref:`install_steps` 。
21+
22+
快速使用
23+
--------
24+
25+
创建一个 housing.py 并粘贴此Python代码:
26+
27+
.. code-block:: python
28+
29+
import paddle.dataset.uci_housing as uci_housing
30+
import paddle.fluid as fluid
31+
32+
with fluid.scope_guard(fluid.core.Scope()):
33+
# initialize executor with cpu
34+
exe = fluid.Executor(place=fluid.CPUPlace())
35+
# load inference model
36+
[inference_program, feed_target_names,fetch_targets] = \
37+
fluid.io.load_inference_model(uci_housing.fluid_model(), exe)
38+
# run inference
39+
result = exe.run(inference_program,
40+
feed={feed_target_names[0]: uci_housing.predict_reader()},
41+
fetch_list=fetch_targets)
42+
# print predicted price is $12,273.97
43+
print 'Predicted price: ${:,.2f}'.format(result[0][0][0] * 1000)
44+
45+
执行 :code:`python housing.py` 瞧! 它应该打印出预测住房数据的清单。

doc/fluid/getstarted/quickstart_en.rst

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Quick Start
2+
============
3+
4+
Quick Install
5+
-------------
6+
7+
You can use pip to install PaddlePaddle with a single command, supports
8+
CentOS 6 above, Ubuntu 14.04 above or MacOS 10.12, with Python 2.7 installed.
9+
Simply run the following command to install, the version is cpu_avx_openblas:
10+
11+
.. code-block:: bash
12+
13+
pip install paddlepaddle
14+
15+
If you need to install GPU version (cuda7.5_cudnn5_avx_openblas), run:
16+
17+
.. code-block:: bash
18+
19+
pip install paddlepaddle-gpu
20+
21+
For more details about installation and build: :ref:`install_steps` .
22+
23+
Quick Use
24+
---------
25+
26+
Create a new file called housing.py, and paste this Python
27+
code:
28+
29+
30+
.. code-block:: python
31+
32+
import paddle.dataset.uci_housing as uci_housing
33+
import paddle.fluid as fluid
34+
35+
with fluid.scope_guard(fluid.core.Scope()):
36+
# initialize executor with cpu
37+
exe = fluid.Executor(place=fluid.CPUPlace())
38+
# load inference model
39+
[inference_program, feed_target_names,fetch_targets] = \
40+
fluid.io.load_inference_model(uci_housing.fluid_model(), exe)
41+
# run inference
42+
result = exe.run(inference_program,
43+
feed={feed_target_names[0]: uci_housing.predict_reader()},
44+
fetch_list=fetch_targets)
45+
# print predicted price is $12,273.97
46+
print 'Predicted price: ${:,.2f}'.format(result[0][0][0] * 1000)
47+
48+
Run :code:`python housing.py` and voila! It should print out a list of predictions
49+
for the test housing data.

python/paddle/dataset/uci_housing.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
parse training set and test set into paddle reader creators.
2020
"""
2121

22+
import os
23+
2224
import numpy as np
25+
import tempfile
26+
import tarfile
2327
import os
2428
import paddle.dataset.common
2529

@@ -34,8 +38,9 @@
3438

3539
UCI_TRAIN_DATA = None
3640
UCI_TEST_DATA = None
37-
URL_MODEL = 'https://github.com/PaddlePaddle/book/raw/develop/01.fit_a_line/fit_a_line.tar'
38-
MD5_MODEL = '52fc3da8ef3937822fcdd87ee05c0c9b'
41+
42+
FLUID_URL_MODEL = 'https://github.com/PaddlePaddle/book/raw/develop/01.fit_a_line/fluid/fit_a_line.fluid.tar'
43+
FLUID_MD5_MODEL = '6e6dd637ccd5993961f68bfbde46090b'
3944

4045

4146
def feature_range(maximums, minimums):
@@ -113,6 +118,29 @@ def reader():
113118
return reader
114119

115120

121+
def fluid_model():
122+
parameter_tar = paddle.dataset.common.download(
123+
FLUID_URL_MODEL, 'uci_housing', FLUID_MD5_MODEL, 'fit_a_line.fluid.tar')
124+
125+
tar = tarfile.TarFile(parameter_tar, mode='r')
126+
dirpath = tempfile.mkdtemp()
127+
tar.extractall(path=dirpath)
128+
129+
return dirpath
130+
131+
132+
def predict_reader():
133+
"""
134+
It returns just one tuple data to do inference.
135+
136+
:return: one tuple data
137+
:rtype: tuple
138+
"""
139+
global UCI_TEST_DATA
140+
load_data(paddle.dataset.common.download(URL, 'uci_housing', MD5))
141+
return (UCI_TEST_DATA[0][:-1], )
142+
143+
116144
def fetch():
117145
paddle.dataset.common.download(URL, 'uci_housing', MD5)
118146

0 commit comments

Comments
 (0)