使用cross_entroy报错,激活函数用sigmoid
Created by: CruiseSun
label = fluid.layers.data(name='label', shape=[1], dtype='int64') cost = fluid.layers.cross_entropy(input=predict, label=label)
报错: File "train.py", line 743, in train train_func=train_func, place=place, optimizer_func=optimizer_func) File "/Users/sunzhenhua/anaconda2/lib/python2.7/site-packages/paddle/fluid/contrib/trainer.py", line 259, in init program_func_outs = train_func() File "train.py", line 728, in train_program cost = fluid.layers.cross_entropy(input=predict, label=label, soft_label=True) File "/Users/sunzhenhua/anaconda2/lib/python2.7/site-packages/paddle/fluid/layers/nn.py", line 1133, in cross_entropy "ignore_index": ignore_index}) File "/Users/sunzhenhua/anaconda2/lib/python2.7/site-packages/paddle/fluid/layer_helper.py", line 50, in append_op return self.main_program.current_block().append_op(*args, kwargs) File "/Users/sunzhenhua/anaconda2/lib/python2.7/site-packages/paddle/fluid/framework.py", line 1207, in append_op op = Operator(block=self, desc=op_desc, args, kwargs) File "/Users/sunzhenhua/anaconda2/lib/python2.7/site-packages/paddle/fluid/framework.py", line 656, in init self.desc.infer_shape(self.block.desc) paddle.fluid.core.EnforceNotMet: Enforce failed. Expected rank == label_dims.size(), but received rank:1 != label_dims.size():2. Input(X) and Input(Label) shall have the same rank. at [/Users/python2/yangjiabin/PR/Paddle/paddle/fluid/operators/cross_entropy_op.cc:33] PaddlePaddle Call Stacks: 0 0x1a1bbb69a8p paddle::platform::EnforceNotMet::EnforceNotMet(std::exception_ptr, char const, int) + 760 1 0x1a1c79d5d8p paddle::operators::CrossEntropyOp::InferShape(paddle::framework::InferShapeContext) const + 3560 2 0x1a1bc73c58p paddle::framework::OpDesc::InferShape(paddle::framework::BlockDesc const&) const + 1496 3 0x1a1bc3d2c9p ZZN8pybind1112cpp_function10initializeIZNS0_C1IvN6paddle9framework6OpDescEJRKNS4_9BlockDescEEJNS_4nameENS_9is_methodENS_7siblingEEEEMT0_KFT_DpT1_EDpRKT2_EUlPKS5_S8_E_vJSN_S8_EJS9_SA_SB_EEEvOSD_PFSC_SF_ESL_ENKUlRNS_6detail13function_callEE_clESU + 185 4 0x1a1bbc12eap pybind11::cpp_function::dispatcher(_object, _object, _object) + 5690 5 0x10e7e4297p PyEval_EvalFrameEx + 22391 6 0x10e7de8c4p PyEval_EvalCodeEx + 2164 7 0x10e760723p function_call + 355 8 0x10e737c55p PyObject_Call + 101