Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
BaiXuePrincess
Paddle
提交
f096af83
P
Paddle
项目概览
BaiXuePrincess
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
未验证
提交
f096af83
编写于
11月 19, 2020
作者:
S
Shibo Tao
提交者:
GitHub
11月 19, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix document sample. test=develop (#28721)
上级
3c5f2cac
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
17 addition
and
21 deletion
+17
-21
python/paddle/static/io.py
python/paddle/static/io.py
+17
-21
未找到文件。
python/paddle/static/io.py
浏览文件 @
f096af83
...
...
@@ -78,23 +78,21 @@ def save_inference_model(path_prefix, feed_vars, fetch_vars, executor):
.. code-block:: python
import paddle
import paddle.fluid as fluid
paddle.enable_static()
path_prefix = "./infer_model"
# User defined network, here a softmax regession example
image = fluid.data(name='img', shape=[None, 28, 28], dtype='float32')
label = fluid.data(name='label', shape=[None, 1], dtype='int64')
feeder = fluid.DataFeeder(feed_list=[image, label], place=fluid.CPUPlace())
predict = fluid.layers.fc(input=image, size=10, act='softmax')
image = paddle.static.data(name='img', shape=[None, 28, 28], dtype='float32')
label = paddle.static.data(name='label', shape=[None, 1], dtype='int64')
predict = paddle.static.nn.fc(image, 10, activation='softmax')
loss =
fluid.layers.cross_entropy(input=predict, label=
label)
avg_loss =
fluid.layers
.mean(loss)
loss =
paddle.nn.functional.cross_entropy(predict,
label)
avg_loss =
paddle.tensor.stat
.mean(loss)
exe =
fluid.Executor(fluid
.CPUPlace())
exe.run(
fluid
.default_startup_program())
exe =
paddle.static.Executor(paddle
.CPUPlace())
exe.run(
paddle.static
.default_startup_program())
# Feed data and train process
...
...
@@ -223,22 +221,20 @@ def load_inference_model(path_prefix, executor, **configs):
.. code-block:: python
import paddle
import paddle.fluid as fluid
import numpy as np
paddle.enable_static()
# Build the model
startup_prog = fluid.default_startup_program()
main_prog = fluid.default_main_program()
with fluid.program_guard(main_prog, startup_prog):
image = fluid.layers.data(name="img", shape=[64, 784], append_batch_size=False)
w = fluid.layers.create_parameter(shape=[784, 200], dtype='float32')
b = fluid.layers.create_parameter(shape=[200], dtype='float32')
hidden_w = fluid.layers.matmul(x=image, y=w)
hidden_b = fluid.layers.elementwise_add(hidden_w, b)
place = fluid.CPUPlace()
exe = fluid.Executor(place)
startup_prog = paddle.static.default_startup_program()
main_prog = paddle.static.default_main_program()
with paddle.static.program_guard(main_prog, startup_prog):
image = paddle.static.data(name="img", shape=[64, 784])
w = paddle.create_parameter(shape=[784, 200], dtype='float32')
b = paddle.create_parameter(shape=[200], dtype='float32')
hidden_w = paddle.matmul(x=image, y=w)
hidden_b = paddle.add(hidden_w, b)
exe = paddle.static.Executor(paddle.CPUPlace())
exe.run(startup_prog)
# Save the inference model
...
...
@@ -247,7 +243,7 @@ def load_inference_model(path_prefix, executor, **configs):
[inference_program, feed_target_names, fetch_targets] = (
paddle.static.io.load_inference_model(path_prefix, exe))
tensor_img = np.array(np.random.random((
1,
64, 784)), dtype=np.float32)
tensor_img = np.array(np.random.random((64, 784)), dtype=np.float32)
results = exe.run(inference_program,
feed={feed_target_names[0]: tensor_img},
fetch_list=fetch_targets)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录