Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
5547a760
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5547a760
编写于
9月 08, 2016
作者:
L
liuyuan04
提交者:
Yu Yang
9月 08, 2016
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refine doc of Python Prediction API, replace
DataProviderWrapperConverter with DataProviderConverter.
上级
903d5c7e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
15 deletion
+23
-15
doc/ui/predict/predict_sample.py
doc/ui/predict/predict_sample.py
+4
-4
doc/ui/predict/swig_py_paddle_en.rst
doc/ui/predict/swig_py_paddle_en.rst
+19
-11
未找到文件。
doc/ui/predict/predict_sample.py
浏览文件 @
5547a760
...
...
@@ -12,8 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from
py_paddle
import
swig_paddle
,
DataProvider
Wrapper
Converter
from
paddle.trainer.PyDataProvider
Wrapper
import
DenseSlot
from
py_paddle
import
swig_paddle
,
DataProviderConverter
from
paddle.trainer.PyDataProvider
2
import
dense_vector
from
paddle.trainer.config_parser
import
parse_config
TEST_DATA
=
[[[
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
0
,
...
...
@@ -89,12 +89,12 @@ TEST_DATA = [[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
def
main
():
conf
=
parse_config
(
"./mnist_model/trainer_config.
conf.norm
"
,
""
)
conf
=
parse_config
(
"./mnist_model/trainer_config.
py
"
,
""
)
print
conf
.
data_config
.
load_data_args
network
=
swig_paddle
.
GradientMachine
.
createFromConfigProto
(
conf
.
model_config
)
assert
isinstance
(
network
,
swig_paddle
.
GradientMachine
)
# For code hint.
network
.
loadParameters
(
"./mnist_model/"
)
converter
=
DataProvider
WrapperConverter
(
False
,
[
DenseSlot
(
784
)])
converter
=
DataProvider
Converter
([
dense_vector
(
784
)])
inArg
=
converter
(
TEST_DATA
)
print
network
.
forwardTest
(
inArg
)
...
...
doc/ui/predict/swig_py_paddle_en.rst
浏览文件 @
5547a760
...
...
@@ -10,27 +10,35 @@ SWIG. The main steps of predict values in python are:
* Predict
Here is a sample python script that shows the typical prediction process for the
MNIST classification problem.
MNIST classification problem. A complete sample code could be found at
:code:`src_root/doc/ui/predict/predict_sample.py`.
.. literalinclude:: ./predict_sample.py
:language: python
:line
nos:
:line
s: 15-18,90-100,101-104
The module that does the most of the job is py_paddle.swig_paddle, it's
generated by SWIG and has complete documents, for more details you can use
python's :code:`help()` function. Let's walk through the above python script:
* At the beginning, initialize PaddlePaddle with command line arguments(line 90).
* Parse the configuration file that is used in training(line 93).
* Create a neural network at line 95 according the parsed configuration, then
load the trained parameters from model at line 97.
* A utility class for data transformation is created at line 98.
* At the beginning, use :code:`swig_paddle.initPaddle()` to initialize
PaddlePaddle with command line arguments, for more about command line arguments
see `Command Line Arguments <../cmd_argument/detail_introduction.html>`_.
* Parse the configuration file that is used in training with :code:`parse_config()`.
Because data to predict with always have no label, and output of prediction work
normally is the output layer rather than the cost layer, so you should modify
the configuration file accordingly before using it in the prediction work.
* Create a neural network with
:code:`swig_paddle.GradientMachine.createFromConfigproto()`, which takes the
parsed configuration :code:`conf.model_config` as argument. Then load the
trained parameters from the model with :code:`network.loadParameters()`.
* Create a data converter object of utility class :code:`DataProviderConverter`.
- Note: As swig_paddle can only accept C++ matrices, we offer a utility
class DataProvider
Wraaper
Converter that can accept the same input data with
PyDataProvider
Wrapper
, for more information please refer to document
class DataProviderConverter that can accept the same input data with
PyDataProvider
2
, for more information please refer to document
of `PyDataProvider2 <../data_provider/pydataprovider2.html>`_.
* Do the prediction
and output the result at line 100, forwardTest is another
utility class that directly take
s the activations of the output layer.
* Do the prediction
with :code:`forwardTest()`, which takes the converted
input data and output
s the activations of the output layer.
Here is a typical output:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录