diff --git a/01.fit_a_line/README.cn.md b/01.fit_a_line/README.cn.md index 936142bfbc427fa085797f2e62b136709e085405..a969c752767a575d78e86bd51d763702b91eb551 100644 --- a/01.fit_a_line/README.cn.md +++ b/01.fit_a_line/README.cn.md @@ -100,6 +100,7 @@ $$MSE=\frac{1}{n}\sum_{i=1}^{n}{(\hat{Y_i}-Y_i)}^2$$ import paddle import paddle.fluid as fluid import numpy +from __future__ import print_function ``` 我们通过uci_housing模块引入了数据集合[UCI Housing Data Set](https://archive.ics.uci.edu/ml/datasets/Housing) @@ -179,7 +180,7 @@ feed_order=['x', 'y'] 除此之外,可以定义一个事件相应器来处理类似`打印训练进程`的事件: ```python -# Specify the directory path to save the parameters +# Specify the directory to save the parameters params_dirname = "fit_a_line.inference.model" # Plot data @@ -190,11 +191,11 @@ plot_cost = Ploter(train_title, test_title) step = 0 -# event_handler to print training and testing info +# event_handler prints training and testing info def event_handler_plot(event): global step if isinstance(event, fluid.EndStepEvent): - if event.step % 10 == 0: # every 10 batches, record a test cost + if event.step % 10 == 0: # record the test cost every 10 seconds test_metrics = trainer.test( reader=test_reader, feed_order=feed_order) @@ -251,10 +252,20 @@ inferencer = fluid.Inferencer( infer_func=inference_program, param_path=params_dirname, place=place) batch_size = 10 -tensor_x = numpy.random.uniform(0, 10, [batch_size, 13]).astype("float32") +test_reader = paddle.batch(paddle.dataset.uci_housing.test(),batch_size=batch_size) +test_data = test_reader().next() +test_feat = numpy.array([data[0] for data in test_data]).astype("float32") +test_label = numpy.array([data[1] for data in test_data]).astype("float32") -results = inferencer.infer({'x': tensor_x}) -print("infer results: ", results[0]) +results = inferencer.infer({'x': test_feat}) + +print("infer results: (House Price)") +for k in range(0, batch_size-1): + print("%d. %f" % (k, results[0][k])) + +print("\nground truth:") +for k in range(0, batch_size-1): + print("%d. %f" % (k, test_label[k])) ``` ## 总结 diff --git a/01.fit_a_line/README.md b/01.fit_a_line/README.md index e672caf1206b13b50abbd57eb2fc465fb656cce1..407d0411eb7a2f3cd990618a22b34eaca0abfd28 100644 --- a/01.fit_a_line/README.md +++ b/01.fit_a_line/README.md @@ -108,6 +108,7 @@ Our program starts with importing necessary packages: import paddle import paddle.fluid as fluid import numpy +from __future__ import print_function ``` We encapsulated the [UCI Housing Data Set](https://archive.ics.uci.edu/ml/datasets/Housing) in our Python module `uci_housing`. This module can @@ -189,7 +190,7 @@ feed_order=['x', 'y'] Moreover, an event handler is provided to print the training progress: ```python -# Specify the directory path to save the parameters +# Specify the directory to save the parameters params_dirname = "fit_a_line.inference.model" # Plot data @@ -200,11 +201,11 @@ plot_cost = Ploter(train_title, test_title) step = 0 -# event_handler to print training and testing info +# event_handler prints training and testing info def event_handler_plot(event): global step if isinstance(event, fluid.EndStepEvent): - if event.step % 10 == 0: # every 10 batches, record a test cost + if event.step % 10 == 0: #record a test cost every 10 batches test_metrics = trainer.test( reader=test_reader, feed_order=feed_order) @@ -263,10 +264,20 @@ inferencer = fluid.Inferencer( infer_func=inference_program, param_path=params_dirname, place=place) batch_size = 10 -tensor_x = numpy.random.uniform(0, 10, [batch_size, 13]).astype("float32") +test_reader = paddle.batch(paddle.dataset.uci_housing.test(),batch_size=batch_size) +test_data = test_reader().next() +test_feat = numpy.array([data[0] for data in test_data]).astype("float32") +test_label = numpy.array([data[1] for data in test_data]).astype("float32") -results = inferencer.infer({'x': tensor_x}) -print("infer results: ", results[0]) +results = inferencer.infer({'x': test_feat}) + +print("infer results: (House Price)") +for k in range(0, batch_size-1): + print("%d. %f" % (k, results[0][k])) + +print("\nground truth:") +for k in range(0, batch_size-1): + print("%d. %f" % (k, test_label[k])) ``` ## Summary diff --git a/01.fit_a_line/image/ranges.png b/01.fit_a_line/image/ranges.png index 5d86b12715f46afbafb7d50e2938e184219b5b95..5325df4800985983e17476f007658d1cdb170b1c 100644 Binary files a/01.fit_a_line/image/ranges.png and b/01.fit_a_line/image/ranges.png differ diff --git a/01.fit_a_line/index.cn.html b/01.fit_a_line/index.cn.html index 32760a22092f136746a72328b48502548caf7692..9a0b9918dcbbb31c4615908b3cc323eb59b36835 100644 --- a/01.fit_a_line/index.cn.html +++ b/01.fit_a_line/index.cn.html @@ -142,6 +142,7 @@ $$MSE=\frac{1}{n}\sum_{i=1}^{n}{(\hat{Y_i}-Y_i)}^2$$ import paddle import paddle.fluid as fluid import numpy +from __future__ import print_function ``` 我们通过uci_housing模块引入了数据集合[UCI Housing Data Set](https://archive.ics.uci.edu/ml/datasets/Housing) @@ -221,7 +222,7 @@ feed_order=['x', 'y'] 除此之外,可以定义一个事件相应器来处理类似`打印训练进程`的事件: ```python -# Specify the directory path to save the parameters +# Specify the directory to save the parameters params_dirname = "fit_a_line.inference.model" # Plot data @@ -232,11 +233,11 @@ plot_cost = Ploter(train_title, test_title) step = 0 -# event_handler to print training and testing info +# event_handler prints training and testing info def event_handler_plot(event): global step if isinstance(event, fluid.EndStepEvent): - if event.step % 10 == 0: # every 10 batches, record a test cost + if event.step % 10 == 0: # record the test cost every 10 seconds test_metrics = trainer.test( reader=test_reader, feed_order=feed_order) @@ -293,10 +294,20 @@ inferencer = fluid.Inferencer( infer_func=inference_program, param_path=params_dirname, place=place) batch_size = 10 -tensor_x = numpy.random.uniform(0, 10, [batch_size, 13]).astype("float32") +test_reader = paddle.batch(paddle.dataset.uci_housing.test(),batch_size=batch_size) +test_data = test_reader().next() +test_feat = numpy.array([data[0] for data in test_data]).astype("float32") +test_label = numpy.array([data[1] for data in test_data]).astype("float32") -results = inferencer.infer({'x': tensor_x}) -print("infer results: ", results[0]) +results = inferencer.infer({'x': test_feat}) + +print("infer results: (House Price)") +for k in range(0, batch_size-1): + print("%d. %f" % (k, results[0][k])) + +print("\nground truth:") +for k in range(0, batch_size-1): + print("%d. %f" % (k, test_label[k])) ``` ## 总结 diff --git a/01.fit_a_line/index.html b/01.fit_a_line/index.html index cab234ff49188aa0be1941c5c81c4c1fc3a9d2a3..4c6cf7f431c599abdae0f6e4109ca571ba613f4d 100644 --- a/01.fit_a_line/index.html +++ b/01.fit_a_line/index.html @@ -150,6 +150,7 @@ Our program starts with importing necessary packages: import paddle import paddle.fluid as fluid import numpy +from __future__ import print_function ``` We encapsulated the [UCI Housing Data Set](https://archive.ics.uci.edu/ml/datasets/Housing) in our Python module `uci_housing`. This module can @@ -231,7 +232,7 @@ feed_order=['x', 'y'] Moreover, an event handler is provided to print the training progress: ```python -# Specify the directory path to save the parameters +# Specify the directory to save the parameters params_dirname = "fit_a_line.inference.model" # Plot data @@ -242,11 +243,11 @@ plot_cost = Ploter(train_title, test_title) step = 0 -# event_handler to print training and testing info +# event_handler prints training and testing info def event_handler_plot(event): global step if isinstance(event, fluid.EndStepEvent): - if event.step % 10 == 0: # every 10 batches, record a test cost + if event.step % 10 == 0: #record a test cost every 10 batches test_metrics = trainer.test( reader=test_reader, feed_order=feed_order) @@ -305,10 +306,20 @@ inferencer = fluid.Inferencer( infer_func=inference_program, param_path=params_dirname, place=place) batch_size = 10 -tensor_x = numpy.random.uniform(0, 10, [batch_size, 13]).astype("float32") +test_reader = paddle.batch(paddle.dataset.uci_housing.test(),batch_size=batch_size) +test_data = test_reader().next() +test_feat = numpy.array([data[0] for data in test_data]).astype("float32") +test_label = numpy.array([data[1] for data in test_data]).astype("float32") -results = inferencer.infer({'x': tensor_x}) -print("infer results: ", results[0]) +results = inferencer.infer({'x': test_feat}) + +print("infer results: (House Price)") +for k in range(0, batch_size-1): + print("%d. %f" % (k, results[0][k])) + +print("\nground truth:") +for k in range(0, batch_size-1): + print("%d. %f" % (k, test_label[k])) ``` ## Summary diff --git a/03.image_classification/README.cn.md b/03.image_classification/README.cn.md index 59180d1db79c88e1986606cf06873559a2b7b961..3f21327ba257806aef5f7464d0708a95421b0d4a 100644 --- a/03.image_classification/README.cn.md +++ b/03.image_classification/README.cn.md @@ -160,6 +160,7 @@ import paddle import paddle.fluid as fluid import numpy import sys +from __future__ import print_function ``` 本教程中我们提供了VGG和ResNet两个模型的配置。 @@ -426,7 +427,7 @@ def event_handler(event): 通过`trainer.train`函数训练: -**注意:** CPU,每个 Epoch 将花费大约15~20分钟。这部分可能需要一段时间。请随意修改代码,在GPU上运行测试,以提高培训速度。 +**注意:** CPU,每个 Epoch 将花费大约15~20分钟。这部分可能需要一段时间。请随意修改代码,在GPU上运行测试,以提高训练速度。 ```python trainer.train( @@ -499,10 +500,10 @@ img = load_image(cur_dir + '/image/dog.png') ```python inferencer = fluid.Inferencer( infer_func=inference_program, param_path=params_dirname, place=place) - +label_list = ["airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck"] # inference results = inferencer.infer({'pixel': img}) -print("infer results: ", results) +print("infer results: %s" % label_list[np.argmax(results[0])]) ``` ## 总结 diff --git a/03.image_classification/README.md b/03.image_classification/README.md index f24fbdeb9458f1730fe64bd6d54b2c71400d4a4e..c3632e9e9a85e66ea8b7ab4ed14ed635c72c9258 100644 --- a/03.image_classification/README.md +++ b/03.image_classification/README.md @@ -171,6 +171,7 @@ import paddle import paddle.fluid as fluid import numpy import sys +from __future__ import print_function ``` Now we are going to walk you through the implementations of the VGG and ResNet. @@ -514,9 +515,10 @@ Now we are ready to do inference. inferencer = fluid.Inferencer( infer_func=inference_program, param_path=params_dirname, place=place) +label_list = ["airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck"] # inference results = inferencer.infer({'pixel': img}) -print("infer results: ", results) +print("infer results: %s" % label_list[np.argmax(results[0])]) ``` diff --git a/03.image_classification/index.cn.html b/03.image_classification/index.cn.html index dbd1f1c5978e91126104309e67527b9243a0fc75..0aa3cf2554cbeb07b57388e405fc0da0bba50665 100644 --- a/03.image_classification/index.cn.html +++ b/03.image_classification/index.cn.html @@ -202,6 +202,7 @@ import paddle import paddle.fluid as fluid import numpy import sys +from __future__ import print_function ``` 本教程中我们提供了VGG和ResNet两个模型的配置。 @@ -468,7 +469,7 @@ def event_handler(event): 通过`trainer.train`函数训练: -**注意:** CPU,每个 Epoch 将花费大约15~20分钟。这部分可能需要一段时间。请随意修改代码,在GPU上运行测试,以提高培训速度。 +**注意:** CPU,每个 Epoch 将花费大约15~20分钟。这部分可能需要一段时间。请随意修改代码,在GPU上运行测试,以提高训练速度。 ```python trainer.train( @@ -541,10 +542,10 @@ img = load_image(cur_dir + '/image/dog.png') ```python inferencer = fluid.Inferencer( infer_func=inference_program, param_path=params_dirname, place=place) - +label_list = ["airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck"] # inference results = inferencer.infer({'pixel': img}) -print("infer results: ", results) +print("infer results: %s" % label_list[np.argmax(results[0])]) ``` ## 总结 diff --git a/03.image_classification/index.html b/03.image_classification/index.html index 0a37e7016c2849bfe9b1c6bf4c1acda864a0b1d0..6c2f1f6643caaab13831f824fbbfdb85644c76ec 100644 --- a/03.image_classification/index.html +++ b/03.image_classification/index.html @@ -213,6 +213,7 @@ import paddle import paddle.fluid as fluid import numpy import sys +from __future__ import print_function ``` Now we are going to walk you through the implementations of the VGG and ResNet. @@ -556,9 +557,10 @@ Now we are ready to do inference. inferencer = fluid.Inferencer( infer_func=inference_program, param_path=params_dirname, place=place) +label_list = ["airplane", "automobile", "bird", "cat", "deer", "dog", "frog", "horse", "ship", "truck"] # inference results = inferencer.infer({'pixel': img}) -print("infer results: ", results) +print("infer results: %s" % label_list[np.argmax(results[0])]) ```