Skip to content

  • 体验新版
    • 正在加载...
  • 登录
  • PaddlePaddle
  • Paddle
  • Issue
  • #21176

P
Paddle
  • 项目概览

PaddlePaddle / Paddle
大约 2 年 前同步成功

通知 2325
Star 20933
Fork 5424
  • 代码
    • 文件
    • 提交
    • 分支
    • 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看板
已关闭
开放中
Opened 11月 14, 2019 by saxon_zh@saxon_zhGuest

windows使用样例保存model后,加载模型,预测出错。

Created by: skriser

在使用官方提供的demo直接训练预测没有问题。当把训练和预测分开执行,在加载模型预测时报错。

这是代码---
"""
usage: https://www.paddlepaddle.org.cn/documentation/docs/zh/beginners_guide/quick_start_cn.html
线性回归模型:借此属性paddle使用
"""
import paddle.fluid as fluid
import numpy as np

# 生成数据
np.random.seed(0)
outputs = np.random.randint(5, size=(10, 4))
res = []
# for i in range(10):
#     # 假设方程式为 y=4a+6b+7c+2d
#     y = 4 * outputs[i][0] + 6 * outputs[i][1] + 7 * outputs[i][2] + 2 * outputs[i][3]
#     res.append([y])
# # 定义数据
# train_data = np.array(outputs).astype('float32')
# y_true = np.array(res).astype('float32')
#
# # 定义网络
# x = fluid.layers.data(name="x", shape=[4], dtype='float32')
# y = fluid.layers.data(name="y", shape=[1], dtype='float32')
# y_predict = fluid.layers.fc(input=x, size=1, act=None)
# # 定义损失函数
# cost = fluid.layers.square_error_cost(input=y_predict, label=y)
# avg_cost = fluid.layers.mean(cost)
# # 定义优化方法
# sgd_optimizer = fluid.optimizer.SGD(learning_rate=0.05)
# sgd_optimizer.minimize(avg_cost)
# # 参数初始化
# cpu = fluid.CPUPlace()
# exe = fluid.Executor(cpu)
# exe.run(fluid.default_startup_program())
# # #开始训练,迭代500次
# for i in range(500):
#     outs = exe.run(
#         feed={'x': train_data, 'y': y_true},
#         fetch_list=[y_predict.name, avg_cost.name])
#     if i % 50 == 0:
#         print('iter={:.0f},cost={}'.format(i, outs[1][0]))
# # 存储训练结果
# params_dirname = "result"
# fluid.io.save_inference_model(params_dirname, ['x'], [y_predict], exe)

# 存储模型后,注释训练过程,使用加载模型方式执行报错
# 开始预测
params_dirname = "result"
cpu = fluid.CPUPlace()
infer_exe = fluid.Executor(cpu)
inference_scope = fluid.Scope()
# 加载训练好的模型
with fluid.scope_guard(inference_scope):
    [inference_program, feed_target_names,
     fetch_targets] = fluid.io.load_inference_model(params_dirname, infer_exe)

# 生成测试数据
test = np.array([[[9], [5], [2], [10]]]).astype('float32')
# 进行预测
results = infer_exe.run(inference_program,
                        feed={"x": test},
                        fetch_list=fetch_targets)
# 给出题目为 【9,5,2,10】 输出y=4*9+6*5+7*2+10*2的值
print("9a+5b+2c+10d={}".format(results[0][0]))

=报错信息==========================================

C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\paddle\fluid\executor.py:774: UserWarning: The following exception is not an EOF exception.
  "The following exception is not an EOF exception.")
Traceback (most recent call last):
  File "C:/xgnews/text-to-text/paddle_learn/lineregression.py", line 63, in <module>
    fetch_list=fetch_targets)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\paddle\fluid\executor.py", line 775, in run
    six.reraise(*sys.exc_info())
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\six.py", line 693, in reraise
    raise value
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\paddle\fluid\executor.py", line 770, in run
    use_program_cache=use_program_cache)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\paddle\fluid\executor.py", line 817, in _run_impl
    use_program_cache=use_program_cache)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\paddle\fluid\executor.py", line 894, in _run_program
    fetch_var_name)
paddle.fluid.core_avx.EnforceNotMet: 

--------------------------------------------
C++ Call Stacks (More useful to developers):
--------------------------------------------
Windows not support stack backtrace yet.

------------------------------------------
Python Call Stacks (More useful to users):
------------------------------------------
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\paddle\fluid\framework.py", line 2459, in append_op
    attrs=kwargs.get("attrs", None))
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\paddle\fluid\layer_helper.py", line 43, in append_op
    return self.main_program.current_block().append_op(*args, **kwargs)
  File "C:\Users\DELL\AppData\Local\Programs\Python\Python36\lib\site-packages\paddle\fluid\layers\nn.py", line 384, in fc
    "y_num_col_dims": 1})
  File "C:/xgnews/text-to-text/paddle_learn/lineregression.py", line 27, in <module>
    y_predict = fluid.layers.fc(input=x, size=1, act=None)

----------------------
Error Message Summary:
----------------------
PaddleCheckError: Expected y_dims.size() > y_num_col_dims, but received y_dims.size():1 <= y_num_col_dims:1.
ShapeError: The input tensor Y's dimensions of MulOp should be larger than y_num_col_dims. But received Y's dimensions = 1, Y's shape = [0], y_num_col_dims = 1. at [D:\1.6.1\paddle\paddle\fluid\operators\mul_op.cc:59]
  [operator < mul > error]
指派人
分配到
无
里程碑
无
分配里程碑
工时统计
无
截止日期
无
标识: paddlepaddle/Paddle#21176
渝ICP备2023009037号

京公网安备11010502055752号

网络110报警服务 Powered by GitLab CE v13.7
开源知识
Git 入门 Pro Git 电子书 在线学 Git
Markdown 基础入门 IT 技术知识开源图谱
帮助
使用手册 反馈建议 博客
《GitCode 隐私声明》 《GitCode 服务条款》 关于GitCode
Powered by GitLab CE v13.7