提交 2dfd8841 编写于 作者: T tangwei12

make quick start code more simpler #9660

上级 d13ca967
......@@ -17,7 +17,7 @@ PaddlePaddle支持使用pip快速安装,目前支持CentOS 6以上, Ubuntu 14.
pip install paddlepaddle-gpu
更详细的安装和编译方法参考: `安装与编译 <http://www.paddlepaddle.org/docs/develop/documentation/fluid/en/build_and_install/index_cn.html>`_
更详细的安装和编译方法参考: :ref:`install_steps`
快速使用
--------
......@@ -25,31 +25,21 @@ PaddlePaddle支持使用pip快速安装,目前支持CentOS 6以上, Ubuntu 14.
创建一个 housing.py 并粘贴此Python代码:
.. code-block:: python
import paddle
import paddle.fluid as fluid
x = fluid.layers.data(name='x', shape=[13], dtype='float32')
place = fluid.CPUPlace()
exe = fluid.Executor(place=place)
feeder = fluid.DataFeeder(place=place, feed_list=[x])
import paddle.dataset.uci_housing as uci_housing
import paddle.fluid as fluid
with fluid.scope_guard(fluid.core.Scope()):
parameter_model = paddle.dataset.uci_housing.fluid_model()
# initialize executor with cpu
exe = fluid.Executor(place=fluid.CPUPlace())
# load inference model
[inference_program, feed_target_names,fetch_targets] = \
fluid.io.load_inference_model(parameter_model, exe)
predict_reader = paddle.batch(paddle.dataset.uci_housing.predict_reader(), batch_size=20)
results = []
for data in predict_reader():
fluid.io.load_inference_model(uci_housing.fluid_model(), exe)
# run inference
result = exe.run(inference_program,
feed=feeder.feed(data),
feed={feed_target_names[0]: uci_housing.predict_reader()},
fetch_list=fetch_targets)
results.append(result)
# print predicted price is $12,273.97
print 'Predicted price: ${:,.2f}'.format(result[0][0][0] * 1000)
for res in results:
for i in xrange(len(res[0])):
print 'Predicted price: ${:,.2f}'.format(res[0][i][0] * 1000)
执行 :code:`python housing.py` 瞧! 它应该打印出预测住房数据的清单。
......@@ -18,7 +18,7 @@ If you need to install GPU version (cuda7.5_cudnn5_avx_openblas), run:
pip install paddlepaddle-gpu
For more details about installation and build: `install and Compile <http://www.paddlepaddle.org/docs/develop/documentation/fluid/en/build_and_install/index_en.html>`_ .
For more details about installation and build: :ref:`install_steps` .
Quick Use
---------
......@@ -28,33 +28,22 @@ code:
.. code-block:: python
import paddle
import paddle.fluid as fluid
x = fluid.layers.data(name='x', shape=[13], dtype='float32')
place = fluid.CPUPlace()
exe = fluid.Executor(place=place)
feeder = fluid.DataFeeder(place=place, feed_list=[x])
import paddle.dataset.uci_housing as uci_housing
import paddle.fluid as fluid
with fluid.scope_guard(fluid.core.Scope()):
parameter_model = paddle.dataset.uci_housing.fluid_model()
# initialize executor with cpu
exe = fluid.Executor(place=fluid.CPUPlace())
# load inference model
[inference_program, feed_target_names,fetch_targets] = \
fluid.io.load_inference_model(parameter_model, exe)
predict_reader = paddle.batch(paddle.dataset.uci_housing.predict_reader(), batch_size=20)
results = []
for data in predict_reader():
fluid.io.load_inference_model(uci_housing.fluid_model(), exe)
# run inference
result = exe.run(inference_program,
feed=feeder.feed(data),
feed={feed_target_names[0]: uci_housing.predict_reader()},
fetch_list=fetch_targets)
results.append(result)
for res in results:
for i in xrange(len(res[0])):
print 'Predicted price: ${:,.2f}'.format(res[0][i][0] * 1000)
# print predicted price is $12,273.97
print 'Predicted price: ${:,.2f}'.format(result[0][0][0] * 1000)
Run :code:`python housing.py` and voila! It should print out a list of predictions
for the test housing data.
......@@ -128,22 +128,14 @@ def fluid_model():
def predict_reader():
"""
UCI_HOUSING test set creator.
It returns a reader creator, each sample in the reader is features after
normalization and price number.
It returns just one tuple data to do inference.
:return: Test reader creator
:rtype: callable
:return: one tuple data
:rtype: tuple
"""
global UCI_TEST_DATA
load_data(paddle.dataset.common.download(URL, 'uci_housing', MD5))
def reader():
for d in UCI_TEST_DATA:
yield (d[:-1],)
return reader
return (UCI_TEST_DATA[0][:-1],)
def fetch():
paddle.dataset.common.download(URL, 'uci_housing', MD5)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册