Paddle icon indicating copy to clipboard operation
Paddle copied to clipboard

paddle.fluid.core.EnforceNotMet: Enforce failed. Expected y_dims.size() > y_num_col_dims

Open lyp2github opened this issue 8 years ago • 4 comments

from utils import logger import paddle.fluid as fluid

main = fluid.Program() startup = fluid.Program() with fluid.program_guard(main, startup): left = fluid.layers.data( name="left", shape=[2], dtype='float32', lod_level=0) right = fluid.layers.data( name="right", shape=[2], dtype='float32', lod_level=0) label = fluid.layers.data( name="label", shape=[1], dtype='int32') fc_left = fluid.layers.fc(input=left, act='relu', size=1) fc_right = fluid.layers.fc(input=right, act='relu', size=1) fc_hid = fluid.layers.fc(input= [fc_left, fc_right], act='relu', size=1) #cos = fluid.layers.rank_loss(fc_label, fc_left, fc_right) cos = fluid.layers.mean(fluid.layers.cross_entropy(input=fc_hid, label=label))

place = fluid.CPUPlace() exe = fluid.Executor(place)

feeder = fluid.DataFeeder(feed_list=[left, right, label], place=place) score_list = exe.run(main, feed=feeder.feed([[[0.5, 0.3], [0.4, 0.2], [1]],[[0.2, 0.6], [0.6, 0.9], [0]]]), )

Traceback (most recent call last): File "t.py", line 31, in feed=feeder.feed([[[0.5, 0.3], [0.4, 0.2], [1]],[[0.2, 0.6], [0.6, 0.9], [0]]]), File "/home/work/liuyaping/paddle/paddle_release_home/python/lib/python2.7/site-packages/paddle/fluid/executor.py", line 470, in run self.executor.run(program.desc, scope, 0, True, True) paddle.fluid.core.EnforceNotMet: Enforce failed. Expected y_dims.size() > y_num_col_dims, but received y_dims.size():1 <= y_num_col_dims:1. The input tensor Y's rank of MulOp should be larger than y_num_col_dims. at [/paddle/paddle/fluid/operators/mul_op.cc:52] PaddlePaddle Call Stacks: 0 0x7f7d018bab02p paddle::platform::EnforceNotMet::EnforceNotMet(std::exception_ptr::exception_ptr, char const*, int) + 482 1 0x7f7d01d8a95ep paddle::operators::MulOp::InferShape(paddle::framework::InferShapeContext*) const + 2894 2 0x7f7d0245317ap paddle::framework::OperatorWithKernel::RunImpl(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void, boost::detail::variant::void, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) const + 74 3 0x7f7d0244f840p paddle::framework::OperatorBase::Run(paddle::framework::Scope const&, boost::variant<paddle::platform::CUDAPlace, paddle::platform::CPUPlace, paddle::platform::CUDAPinnedPlace, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_, boost::detail::variant::void_> const&) + 224 4 0x7f7d01973ea2p paddle::framework::Executor::RunPreparedContext(paddle::framework::ExecutorPrepareContext*, paddle::framework::Scope*, bool, bool, bool) + 226 5 0x7f7d019747e5p paddle::framework::Executor::Run(paddle::framework::ProgramDesc const&, paddle::framework::Scope*, int, bool, bool) + 117 6 0x7f7d018a2bfap 7 0x7f7d018ebbb2p pybind11::cpp_function::dispatcher(_object*, _object*, _object*) + 2338 8 0x7f7d9296dbb8p PyEval_EvalFrameEx + 25016 9 0x7f7d929710bdp PyEval_EvalCodeEx + 2061 10 0x7f7d9296e345p PyEval_EvalFrameEx + 26949 11 0x7f7d929710bdp PyEval_EvalCodeEx + 2061 12 0x7f7d929711f2p PyEval_EvalCode + 50 13 0x7f7d92999f42p PyRun_FileExFlags + 146 14 0x7f7d9299b2d9p PyRun_SimpleFileExFlags + 217 15 0x7f7d929b100dp Py_Main + 3149 16 0x7f7d91baebd5p __libc_start_main + 245 17 0x4007a1p

lyp2github avatar Nov 01 '18 02:11 lyp2github

检查一下定义的数据的Shape和feed的数据是否匹配

seiriosPlus avatar Nov 01 '18 02:11 seiriosPlus

left = fluid.layers.data(
     name="left",
     shape=[1],
     dtype='float32')
right = fluid.layers.data(
     name="right",
     shape=[1],
     dtype='float32')
label = fluid.layers.data(
    name="label",
    shape=[1],
    dtype='int32')

lyp2github avatar Nov 01 '18 03:11 lyp2github

feeder = fluid.DataFeeder(feed_list=[left, right, label], place=place) score_list = exe.run(main, feed=feeder.feed([[[0.5, 0.3], [0.4, 0.2], [1]],[[0.2, 0.6], [0.6, 0.9], [0]]]), fetch_list=[left, right, cos], return_numpy = True, ) [array([[0.5, 0.3], [0.2, 0.6]], dtype=float32), array([[0.4, 0.2], [0.6, 0.9]], dtype=float32), array([[1], [0]], dtype=int32)]

这样获取是成功的,但fc层就报错,是data输入的格式有错?

lyp2github avatar Nov 01 '18 03:11 lyp2github

在执行run main_program之前需要先执行初始化, exe.run(startup)

seiriosPlus avatar Nov 01 '18 03:11 seiriosPlus