diff --git a/doc/fluid/getstarted/quickstart_cn.rst b/doc/fluid/getstarted/quickstart_cn.rst index ecd6ed016aae5db7315cd5a62e75e55b7a4fd4f1..135beb75d0330f39d062753aa2aa83a077f36bb1 100644 --- a/doc/fluid/getstarted/quickstart_cn.rst +++ b/doc/fluid/getstarted/quickstart_cn.rst @@ -17,7 +17,7 @@ PaddlePaddle支持使用pip快速安装,目前支持CentOS 6以上, Ubuntu 14. pip install paddlepaddle-gpu -更详细的安装和编译方法参考: `安装与编译 `_ 。 +更详细的安装和编译方法参考: :ref:`install_steps` 。 快速使用 -------- @@ -25,31 +25,21 @@ PaddlePaddle支持使用pip快速安装,目前支持CentOS 6以上, Ubuntu 14. 创建一个 housing.py 并粘贴此Python代码: .. code-block:: python - import paddle + + import paddle.dataset.uci_housing as uci_housing 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]) - + 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(): - result = exe.run(inference_program, - feed=feeder.feed(data), - 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) + fluid.io.load_inference_model(uci_housing.fluid_model(), exe) + # run inference + result = exe.run(inference_program, + feed={feed_target_names[0]: uci_housing.predict_reader()}, + fetch_list=fetch_targets) + # print predicted price is $12,273.97 + print 'Predicted price: ${:,.2f}'.format(result[0][0][0] * 1000) + 执行 :code:`python housing.py` 瞧! 它应该打印出预测住房数据的清单。 diff --git a/doc/fluid/getstarted/quickstart_en.rst b/doc/fluid/getstarted/quickstart_en.rst index 400cf6d29bf8744bca75a95312daab90be0b6920..df6619cfd039fc1fdca8cde57db9cc6aebf8f029 100644 --- a/doc/fluid/getstarted/quickstart_en.rst +++ b/doc/fluid/getstarted/quickstart_en.rst @@ -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 `_ . +For more details about installation and build: :ref:`install_steps` . Quick Use --------- @@ -28,33 +28,22 @@ code: .. code-block:: python - import paddle + + import paddle.dataset.uci_housing as uci_housing 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]) - + 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(): - result = exe.run(inference_program, - feed=feeder.feed(data), - 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) + fluid.io.load_inference_model(uci_housing.fluid_model(), exe) + # run inference + result = exe.run(inference_program, + feed={feed_target_names[0]: uci_housing.predict_reader()}, + fetch_list=fetch_targets) + # 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. diff --git a/python/paddle/dataset/uci_housing.py b/python/paddle/dataset/uci_housing.py index 8da08249b52be932b4e51fe84f705743e9a176b0..1a5e2a39446f67f430e524a75082ac003fc73d9e 100644 --- a/python/paddle/dataset/uci_housing.py +++ b/python/paddle/dataset/uci_housing.py @@ -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)