Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
book
提交
08e3e11e
B
book
项目概览
PaddlePaddle
/
book
通知
16
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
40
列表
看板
标记
里程碑
合并请求
37
Wiki
5
Wiki
分析
仓库
DevOps
项目成员
Pages
B
book
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
40
Issue
40
列表
看板
标记
里程碑
合并请求
37
合并请求
37
Pages
分析
分析
仓库分析
DevOps
Wiki
5
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
08e3e11e
编写于
6月 01, 2018
作者:
W
Wang,Jeff
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make the inferencer part easier to read.
上级
106e6ae1
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
50 addition
and
12 deletion
+50
-12
02.recognize_digits/README.md
02.recognize_digits/README.md
+25
-6
02.recognize_digits/index.html
02.recognize_digits/index.html
+25
-6
未找到文件。
02.recognize_digits/README.md
浏览文件 @
08e3e11e
...
...
@@ -340,7 +340,10 @@ def event_handler_plot(event):
lists.append((event.epoch, avg_cost, acc))
```
#### Start training
Now that we setup the event_handler and the reader, we can start training the model. `feed_order` is used to map the data dict to the train_program
```
python
# Train the model now
trainer.train(
...
...
@@ -381,6 +384,24 @@ Usually, with MNIST data, the softmax regression model achieves an accuracy arou
After training, users can use the trained model to classify images. The following code shows how to inference MNIST images through `fluid.Inferencer`.
### Create Inferencer
The `Inferencer` takes an `infer_func` and `param_path` to setup the network and the trained parameters.
We can simply plug-in the classifier defined earlier here.
```
python
inferencer = fluid.Inferencer(
# infer_func=softmax_regression, # uncomment for softmax regression
# infer_func=multilayer_perceptron, # uncomment for MLP
infer_func=convolutional_neural_network, # uncomment for LeNet5
param_path=params_dirname,
place=place)
```
#### Generate input data for inferring
`infer_3.png` is an example image of the digit `3`. Turn it into an numpy array to match the data feeder format.
```
python
# Prepare the test image
import os
...
...
@@ -395,15 +416,13 @@ def load_image(file):
cur_dir = cur_dir = os.getcwd()
img = load_image(cur_dir + '/image/infer_3.png')
```
### Inference
inferencer = fluid.Inferencer(
# infer_func=softmax_regression, # uncomment for softmax regression
# infer_func=multilayer_perceptron, # uncomment for MLP
infer_func=convolutional_neural_network, # uncomment for LeNet5
param_path=params_dirname,
place=place)
Now we are ready to do inference.
```
python
results = inferencer.infer({'img': img})
lab = np.argsort(results) # probs and lab are the results of one batch data
print "Label of image/infer_3.png is: %d" % lab
[
0
][
0
]
[-1]
...
...
02.recognize_digits/index.html
浏览文件 @
08e3e11e
...
...
@@ -382,7 +382,10 @@ def event_handler_plot(event):
lists.append((event.epoch, avg_cost, acc))
```
#### Start training
Now that we setup the event_handler and the reader, we can start training the model. `feed_order` is used to map the data dict to the train_program
```python
# Train the model now
trainer.train(
...
...
@@ -423,6 +426,24 @@ Usually, with MNIST data, the softmax regression model achieves an accuracy arou
After training, users can use the trained model to classify images. The following code shows how to inference MNIST images through `fluid.Inferencer`.
### Create Inferencer
The `Inferencer` takes an `infer_func` and `param_path` to setup the network and the trained parameters.
We can simply plug-in the classifier defined earlier here.
```python
inferencer = fluid.Inferencer(
# infer_func=softmax_regression, # uncomment for softmax regression
# infer_func=multilayer_perceptron, # uncomment for MLP
infer_func=convolutional_neural_network, # uncomment for LeNet5
param_path=params_dirname,
place=place)
```
#### Generate input data for inferring
`infer_3.png` is an example image of the digit `3`. Turn it into an numpy array to match the data feeder format.
```python
# Prepare the test image
import os
...
...
@@ -437,15 +458,13 @@ def load_image(file):
cur_dir = cur_dir = os.getcwd()
img = load_image(cur_dir + '/image/infer_3.png')
```
### Inference
inferencer = fluid.Inferencer(
# infer_func=softmax_regression, # uncomment for softmax regression
# infer_func=multilayer_perceptron, # uncomment for MLP
infer_func=convolutional_neural_network, # uncomment for LeNet5
param_path=params_dirname,
place=place)
Now we are ready to do inference.
```python
results = inferencer.infer({'img': img})
lab = np.argsort(results) # probs and lab are the results of one batch data
print "Label of image/infer_3.png is: %d" % lab[0][0][-1]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录