首页 Paddle框架 帖子详情
想知道为什么paddlepaddle会报这个错误
收藏
快速回复
Paddle框架 问答深度学习 3630 6
想知道为什么paddlepaddle会报这个错误
收藏
快速回复
Paddle框架 问答深度学习 3630 6

代码是这样的:

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import paddle
import paddle.fluid as fluid

#设置随机数种子
np.random.seed(5)

#采用np生成100个点的等差数列,每个点取值在[-1,1]之间

x_data = np.linspace(-1,1,100)

#规定线性模型为 y = 2x +1+噪声
#coding here...
y_data = 2*x_data+1+np.random.randn(*x_data.shape)*0.4

# # 构建模型

#定义模型函数
#coding here...
x = fluid.layers.data(name='x', shape=[100], dtype='float32')
y = fluid.layers.data(name='y', shape=[100], dtype='float32')
y_predict = fluid.layers.fc(input=x,size=100,bias_attr=True)


#定义损失函数
#补全下面代码
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.001)
sgd_optimizer.minimize(avg_cost)


#参数初始化
cpu = fluid.core.CPUPlace()
exe = fluid.Executor(cpu)
#exe.run(fluid.default_startup_program())

 


##开始训练,迭代100次
for i in range(100):
for idx in range(len(y_data)):
train_x = np.array(x_data[idx]).astype("float32").reshape((1,1))
label_y = np.array(y_data[idx]).astype("float32").reshape((1,1))
outs = exe.run(
feed={'x':x_data},
fetch_list=[y_predict.name,avg_cost.name])

print("正在训练第" + str(i+1) + "次")
#观察结果
print (outs)

 

报错:

in
36 outs = exe.run(
37 feed={'x':x_data},
---> 38 fetch_list=[y_predict.name,avg_cost.name])
39
40 print("正在训练第" + str(i+1) + "次")
/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/paddle/fluid/executor.py in run(self, program, feed, fetch_list, feed_var_name, fetch_var_name, scope, return_numpy, use_program_cache)
648 scope=scope,
649 return_numpy=return_numpy,
--> 650 use_program_cache=use_program_cache)
651 else:
652 if fetch_list and program._is_data_parallel and program._program and (
/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/paddle/fluid/executor.py in _run(self, program, exe, feed, fetch_list, feed_var_name, fetch_var_name, scope, return_numpy, use_program_cache)
746 self._feed_data(program, feed, feed_var_name, scope)
747 if not use_program_cache:
--> 748 exe.run(program.desc, scope, 0, True, True, fetch_var_name)
749 else:
750 exe.run_cached_prepared_ctx(ctx, scope, False, False, False)
EnforceNotMet: Invoke operator mul error.
Python Callstacks:
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/paddle/fluid/framework.py", line 1748, in append_op
attrs=kwargs.get("attrs", None))
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/paddle/fluid/layer_helper.py", line 43, in append_op
return self.main_program.current_block().append_op(*args, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/paddle/fluid/layers/nn.py", line 333, in fc
"y_num_col_dims": 1})
File "", line 8, in
y_predict = fluid.layers.fc(input=x,size=100,bias_attr=True)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 3265, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 3183, in run_ast_nodes
if (yield from self.run_code(code, result)):
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 3018, in run_cell_async
interactivity=interactivity, compiler=compiler, result=result)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/IPython/core/async_helpers.py", line 67, in _pseudo_sync_runner
coro.send(None)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2843, in _run_cell
return runner(coro)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2817, in run_cell
raw_cell, store_history, silent, shell_futures)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/ipykernel/zmqshell.py", line 536, in run_cell
return super(ZMQInteractiveShell, self).run_cell(*args, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/ipykernel/ipkernel.py", line 294, in do_execute
res = shell.run_cell(code, store_history=store_history, silent=silent)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/tornado/gen.py", line 326, in wrapper
yielded = next(result)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 534, in execute_request
user_expressions, allow_stdin,
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/tornado/gen.py", line 326, in wrapper
yielded = next(result)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 267, in dispatch_shell
yield gen.maybe_future(handler(stream, idents, msg))
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/tornado/gen.py", line 326, in wrapper
yielded = next(result)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 357, in process_one
yield gen.maybe_future(dispatch(*args))
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/tornado/gen.py", line 1080, in __init__
self.run()
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/tornado/gen.py", line 346, in wrapper
runner = Runner(result, future, yielded)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/ipykernel/kernelbase.py", line 370, in dispatch_queue
yield self.process_one()
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/tornado/gen.py", line 1147, in run
yielded = self.gen.send(value)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/tornado/gen.py", line 1233, in inner
self.run()
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/tornado/stack_context.py", line 300, in null_wrapper
return fn(*args, **kwargs)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/tornado/ioloop.py", line 758, in _run_callback
ret = callback()
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/asyncio/events.py", line 127, in _run
self._callback(*self._args)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/asyncio/base_events.py", line 1425, in _run_once
handle._run()
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/asyncio/base_events.py", line 421, in run_forever
self._run_once()
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/tornado/platform/asyncio.py", line 132, in start
self.asyncio_loop.run_forever()
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/ipykernel/kernelapp.py", line 505, in start
self.io_loop.start()
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/traitlets/config/application.py", line 658, in launch_instance
app.start()
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/site-packages/ipykernel_launcher.py", line 16, in
app.launch_new_instance()
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/opt/conda/envs/python35-paddle120-env/lib/python3.5/runpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
C++ Callstacks:
Input Y(0) is not initialized at [/paddle/paddle/fluid/framework/operator.cc:1146]
PaddlePaddle Call Stacks:
0 0x7fa93bbb3600p void paddle::platform::EnforceNotMet::Init(char const*, char const*, int) + 352
1 0x7fa93bbb3979p paddle::platform::EnforceNotMet::EnforceNotMet(std::__exception_ptr::exception_ptr, char const*, int) + 137
2 0x7fa93cef2f2fp paddle::framework::OperatorWithKernel::IndicateDataType(paddle::framework::ExecutionContext const&) const + 1343
3 0x7fa93cef311fp paddle::framework::OperatorWithKernel::GetExpectedKernelType(paddle::framework::ExecutionContext const&) const + 47
4 0x7fa93cef4a0bp paddle::framework::OperatorWithKernel::ChooseKernel(paddle::framework::RuntimeContext const&, paddle::framework::Scope const&, boost::variant const&) const + 235
5 0x7fa93cef5ec8p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant const&, paddle::framework::RuntimeContext*) const + 728
6 0x7fa93cef64d1p paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant const&) const + 529
7 0x7fa93cef437bp paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, boost::variant const&) + 267
8 0x7fa93bd3242ep paddle::framework::Executor::RunPreparedContext(paddle::framework::ExecutorPrepareContext*, paddle::framework::Scope*, bool, bool, bool) + 206
9 0x7fa93bd354afp paddle::framework::Executor::Run(paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool, std::vector > const&, bool) + 143
10 0x7fa93bba5e5dp
11 0x7fa93bbe2956p
12 0x7fa981d45199p PyCFunction_Call + 233
13 0x7fa981de03f9p PyEval_EvalFrameEx + 33545
14 0x7fa981de24b6p
15 0x7fa981ddf5b5p PyEval_EvalFrameEx + 29893
16 0x7fa981de24b6p
17 0x7fa981ddf5b5p PyEval_EvalFrameEx + 29893
18 0x7fa981de24b6p
19 0x7fa981de25a8p PyEval_EvalCodeEx + 72
20 0x7fa981de25ebp PyEval_EvalCode + 59
21 0x7fa981dd5c5dp
22 0x7fa981d45179p PyCFunction_Call + 201
23 0x7fa981ddfdbep PyEval_EvalFrameEx + 31950
24 0x7fa981d19410p _PyGen_Send + 128
25 0x7fa981dde953p PyEval_EvalFrameEx + 26723
26 0x7fa981d19410p _PyGen_Send + 128
27 0x7fa981dde953p PyEval_EvalFrameEx + 26723
28 0x7fa981d19410p _PyGen_Send + 128
29 0x7fa981ddfd60p PyEval_EvalFrameEx + 31856
30 0x7fa981de01d0p PyEval_EvalFrameEx + 32992
31 0x7fa981de01d0p PyEval_EvalFrameEx + 32992
32 0x7fa981de24b6p
33 0x7fa981de25a8p PyEval_EvalCodeEx + 72
34 0x7fa981d21c33p
35 0x7fa981cf033ap PyObject_Call + 106
36 0x7fa981dda6eep PyEval_EvalFrameEx + 9726
37 0x7fa981de24b6p
38 0x7fa981ddf5b5p PyEval_EvalFrameEx + 29893
39 0x7fa981d186bap
40 0x7fa981dd3af6p
41 0x7fa981d45179p PyCFunction_Call + 201
42 0x7fa981ddfdbep PyEval_EvalFrameEx + 31950
43 0x7fa981de24b6p
44 0x7fa981ddf5b5p PyEval_EvalFrameEx + 29893
45 0x7fa981d186bap
46 0x7fa981dd3af6p
47 0x7fa981d45179p PyCFunction_Call + 201
48 0x7fa981ddfdbep PyEval_EvalFrameEx + 31950
49 0x7fa981de24b6p
50 0x7fa981ddf5b5p PyEval_EvalFrameEx + 29893
51 0x7fa981d186bap
52 0x7fa981dd3af6p
53 0x7fa981d45179p PyCFunction_Call + 201
54 0x7fa981ddfdbep PyEval_EvalFrameEx + 31950
55 0x7fa981de24b6p
56 0x7fa981de25a8p PyEval_EvalCodeEx + 72
57 0x7fa981d21b56p
58 0x7fa981cf033ap PyObject_Call + 106
59 0x7fa981dda6eep PyEval_EvalFrameEx + 9726
60 0x7fa981d19410p _PyGen_Send + 128
61 0x7fa981ddfd60p PyEval_EvalFrameEx + 31856
62 0x7fa981de01d0p PyEval_EvalFrameEx + 32992
63 0x7fa981de24b6p
64 0x7fa981de25a8p PyEval_EvalCodeEx + 72
65 0x7fa981d21b56p
66 0x7fa981cf033ap PyObject_Call + 106
67 0x7fa981d08d7dp
68 0x7fa981cf033ap PyObject_Call + 106
69 0x7fa981d61289p
70 0x7fa981d5bfd6p
71 0x7fa981cf033ap PyObject_Call + 106
72 0x7fa981ddc4c5p PyEval_EvalFrameEx + 17365
73 0x7fa981de24b6p
74 0x7fa981ddf5b5p PyEval_EvalFrameEx + 29893
75 0x7fa981d19410p _PyGen_Send + 128
76 0x7fa981ddfd60p PyEval_EvalFrameEx + 31856
77 0x7fa981de01d0p PyEval_EvalFrameEx + 32992
78 0x7fa981de24b6p
79 0x7fa981de25a8p PyEval_EvalCodeEx + 72
80 0x7fa981d21c33p
81 0x7fa981cf033ap PyObject_Call + 106
82 0x7fa981dda6eep PyEval_EvalFrameEx + 9726
83 0x7fa981de24b6p
84 0x7fa981de25a8p PyEval_EvalCodeEx + 72
85 0x7fa981d21b56p
86 0x7fa981cf033ap PyObject_Call + 106
87 0x7fa981e55ccap
88 0x7fa981cf033ap PyObject_Call + 106
89 0x7fa981ddc4c5p PyEval_EvalFrameEx + 17365
90 0x7fa981de24b6p
91 0x7fa981de25a8p PyEval_EvalCodeEx + 72
92 0x7fa981d21b56p
93 0x7fa981cf033ap PyObject_Call + 106
94 0x7fa981dda6eep PyEval_EvalFrameEx + 9726
95 0x7fa981de01d0p PyEval_EvalFrameEx + 32992
96 0x7fa981de01d0p PyEval_EvalFrameEx + 32992
97 0x7fa981de01d0p PyEval_EvalFrameEx + 32992
98 0x7fa981de01d0p PyEval_EvalFrameEx + 32992
99 0x7fa981de01d0p PyEval_EvalFrameEx + 32992

0
收藏
回复
全部评论(6)
时间顺序
A
AIStudio133441
#2 回复于2019-11

同问,也遇到了这个问题

0
回复
thinc
#3 回复于2020-04

cost = fluid.layers.square_error_cost(input=y_predict,label=y)

 

我想问题应该是出现在这一句,因为你用layers.data创建的y并没有有效值(这其实是规定的),所以在计算input和label的误差便会出问题。

 

我想你手上应该是有真实的值,具体实现可以参考下full_constant的使用

0
回复
东海鱼
#4 回复于2020-04

我也碰到这个问题了,请问解决了吗

0
回复
MLTcola
#5 回复于2020-05
我也碰到这个问题了,请问解决了吗

我也是

0
回复
星光ld1
#6 回复于2020-05

你这个实现有满多问题的如果我看的没错的话,期望是做一个R->R的线性模型输入和输出都是一维度的而不是100维网络FC size应该也是100

0
回复
星光ld1
#7 回复于2020-05

下面给出我的对应实现

%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import paddle
import paddle.fluid as fluid

#设置随机数种子
np.random.seed(5)

#采用np生成100个点的等差数列,每个点取值在[-1,1]之间
x_data = np.linspace(-1,1,100)
#规定线性模型为 y = 2x +1+噪声
#coding here...
y_data = 2*x_data+1+np.random.randn(*x_data.shape)*0.4

# # 构建模型
#定义模型函数
#coding here...
x = fluid.layers.data(name='x', shape=[1], dtype='float32')
y = fluid.layers.data(name='y', shape=[1], dtype='float32')
y_predict = fluid.layers.fc(input=x,size=1,bias_attr=True)
#定义损失函数
#补全下面代码
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.001)
opts = sgd_optimizer.minimize(avg_cost)

#参数初始化
cpu = fluid.core.CPUPlace()
exe = fluid.Executor(cpu)
exe.run(fluid.default_startup_program())
feeder = fluid.DataFeeder(place=cpu, feed_list=[x, y])

##开始训练,迭代100次
for i in range(100):
    for idx in range(len(y_data)):
        train_x = np.array(x_data[idx]).astype("float32").reshape((1,1))
        label_y = np.array(y_data[idx]).astype("float32").reshape((1,1))
        outs = exe.run(
            program=fluid.default_main_program(),
            feed=feeder.feed(zip(train_x, label_y)),
            fetch_list=[y_predict.name,avg_cost.name]
        )

    print("正在训练第" + str(i+1) + "次")
#观察结果
print (outs)

除了对模型的理解有问题外,错误产生应该是feeder的定义和使用存在问题,具体可以参考我的实现

0
回复
需求/bug反馈?一键提issue告诉我们
发现bug?如果您知道修复办法,欢迎提pr直接参与建设飞桨~
在@后输入用户全名并按空格结束,可艾特全站任一用户