问题描述:使用百度飞桨训练自己搭建的模型时,在运行到:
optimizer=fluid.optimizer.Adam(learning_rate=0.001)
optimizer.minimize(avg_loss)
出现了这样一个错误。如下所示:
---------------------------------------------------------------------------EnforceNotMetTraceback (mostrecentcalllast)<ipython-input-114-71baa0f01aff>in<module>1# 配置优化器(Optimizer Function) 随机梯度下降SGD 学习率为0.0012sgd_optimezer=fluid.optimizer.SGD(learning_rate=0.1) # learning_rate为学习率---->3sgd_optimezer.minimize(avg_loss) </opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/decorator.py:decorator-gen-145>inminimize(self, loss, startup_program, parameter_list, no_grad_set, grad_clip) /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/wrapped_decorator.pyin__impl__(func, *args, **kwargs) 23def__impl__(func, *args, **kwargs): 24wrapped_func=decorator_func(func) --->25returnwrapped_func(*args, **kwargs) 2627return__impl__/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/dygraph/base.pyin__impl__(*args, **kwargs) 85def__impl__(*args, **kwargs): 86with_switch_tracer_mode_guard_(is_train=False): --->87returnfunc(*args, **kwargs) 8889return__impl__/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/optimizer.pyinminimize(self, loss, startup_program, parameter_list, no_grad_set, grad_clip) 592startup_program=startup_program, 593parameter_list=parameter_list, -->594no_grad_set=no_grad_set)595596ifgrad_clipisnotNoneandframework.in_dygraph_mode(): /opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/optimizer.pyinbackward(self, loss, startup_program, parameter_list, no_grad_set, callbacks) 491withprogram_guard(program, startup_program): 492params_grads=append_backward(loss, parameter_list, -->493no_grad_set, callbacks) 494# Note: since we can't use all_reduce_op now,495# dgc_op should be the last op of one grad./opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/backward.pyinappend_backward(loss, parameter_list, no_grad_set, callbacks) 569grad_to_var, 570callbacks, -->571input_grad_names_set=input_grad_names_set)572573# Because calc_gradient may be called multiple times,/opt/conda/envs/python35-paddle120-env/lib/python3.7/site-packages/paddle/fluid/backward.pyin_append_backward_ops_(block, ops, target_block, no_grad_dict, grad_to_var, callbacks, input_grad_names_set) 308# Getting op's corresponding grad_op309grad_op_desc, op_grad_to_var=core.get_grad_op_desc( -->310op.desc, cpt.to_text(no_grad_dict[block.idx]), grad_sub_block_list) 311312# If input_grad_names_set is not None, extend grad_op_descs only whenEnforceNotMet: grad_op_maker_shouldnotbenullOperatorGradOpMakerhasnotbeenregistered. at [/paddle/paddle/fluid/framework/op_info.h:69] PaddlePaddleCallStacks: 00x7efdea8b2c28pvoidpaddle::platform::EnforceNotMet::Init<std::string>(std::string, charconst*, int) +36010x7efdea8b2f77ppaddle::platform::EnforceNotMet::EnforceNotMet(std::stringconst&, charconst*, int) +8720x7efdea8b3dacppaddle::framework::OpInfo::GradOpMaker() const+10830x7efdea8ac83ep40x7efdea8e1af6p50x559b94463744p_PyMethodDef_RawFastCallKeywords+59660x559b94463861p_PyCFunction_FastCallKeywords+3370x559b944cf2bdp_PyEval_EvalFrameDefault+2017380x559b94413539p_PyEval_EvalCodeWithName+76190x559b94462f57p_PyFunction_FastCallKeywords+903100x559b944cb8ccp_PyEval_EvalFrameDefault+5340110x559b94413539p_PyEval_EvalCodeWithName+761120x559b94462ef5p_PyFunction_FastCallKeywords+805130x559b944ca806p_PyEval_EvalFrameDefault+1046140x559b94413539p_PyEval_EvalCodeWithName+761150x559b94462f57p_PyFunction_FastCallKeywords+903160x559b944cb8ccp_PyEval_EvalFrameDefault+5340170x559b94413539p_PyEval_EvalCodeWithName+761180x559b94414635p_PyFunction_FastCallDict+469190x559b944cc232p_PyEval_EvalFrameDefault+7746200x559b9441381ap_PyEval_EvalCodeWithName+1498210x559b94414635p_PyFunction_FastCallDict+469220x559b944cc232p_PyEval_EvalFrameDefault+7746230x559b9441381ap_PyEval_EvalCodeWithName+1498240x559b94462f57p_PyFunction_FastCallKeywords+903250x559b944ca806p_PyEval_EvalFrameDefault+1046260x559b94413539p_PyEval_EvalCodeWithName+761270x559b94462ef5p_PyFunction_FastCallKeywords+805280x559b944caa93p_PyEval_EvalFrameDefault+1699290x559b94413539p_PyEval_EvalCodeWithName+761300x559b94414424pPyEval_EvalCodeEx+68310x559b9441444cpPyEval_EvalCode+28320x559b944d9f8dp330x559b944635d9p_PyMethodDef_RawFastCallKeywords+233340x559b94463861p_PyCFunction_FastCallKeywords+33350x559b944ceb94p_PyEval_EvalFrameDefault+18340360x559b9446c592p_PyGen_Send+674370x559b944cbe69p_PyEval_EvalFrameDefault+6777380x559b9446c592p_PyGen_Send+674390x559b944cbe69p_PyEval_EvalFrameDefault+6777400x559b9446c592p_PyGen_Send+674410x559b9446357dp_PyMethodDef_RawFastCallKeywords+141420x559b9446b3cfp_PyMethodDescr_FastCallKeywords+79430x559b944cf07cp_PyEval_EvalFrameDefault+19596440x559b94462ccbp_PyFunction_FastCallKeywords+251450x559b944ca806p_PyEval_EvalFrameDefault+1046460x559b94462ccbp_PyFunction_FastCallKeywords+251470x559b944caa93p_PyEval_EvalFrameDefault+1699480x559b94413539p_PyEval_EvalCodeWithName+761490x559b94414860p_PyFunction_FastCallDict+1024500x559b94432e53p_PyObject_Call_Prepend+99510x559b94425dbepPyObject_Call+110520x559b944cc232p_PyEval_EvalFrameDefault+7746530x559b9441381ap_PyEval_EvalCodeWithName+1498540x559b94462f57p_PyFunction_FastCallKeywords+903550x559b944cb8ccp_PyEval_EvalFrameDefault+5340560x559b9446c059p570x559b944635d9p_PyMethodDef_RawFastCallKeywords+233580x559b94463861p_PyCFunction_FastCallKeywords+33590x559b944ceb94p_PyEval_EvalFrameDefault+18340600x559b9441381ap_PyEval_EvalCodeWithName+1498610x559b94462f57p_PyFunction_FastCallKeywords+903620x559b944caa93p_PyEval_EvalFrameDefault+1699630x559b9446c059p640x559b944635d9p_PyMethodDef_RawFastCallKeywords+233650x559b94463861p_PyCFunction_FastCallKeywords+33660x559b944ceb94p_PyEval_EvalFrameDefault+18340670x559b9441381ap_PyEval_EvalCodeWithName+1498680x559b94462f57p_PyFunction_FastCallKeywords+903690x559b944ca806p_PyEval_EvalFrameDefault+1046700x559b9446c059p710x559b944635d9p_PyMethodDef_RawFastCallKeywords+233720x559b94463861p_PyCFunction_FastCallKeywords+33730x559b944ceb94p_PyEval_EvalFrameDefault+18340740x559b9441381ap_PyEval_EvalCodeWithName+1498750x559b94414635p_PyFunction_FastCallDict+469760x559b94432e53p_PyObject_Call_Prepend+99770x559b94425dbepPyObject_Call+110780x559b944cc232p_PyEval_EvalFrameDefault+7746790x559b9446c43cp_PyGen_Send+332800x559b9446357dp_PyMethodDef_RawFastCallKeywords+141810x559b9446b3cfp_PyMethodDescr_FastCallKeywords+79820x559b944cf07cp_PyEval_EvalFrameDefault+19596830x559b94462ccbp_PyFunction_FastCallKeywords+251840x559b944caa93p_PyEval_EvalFrameDefault+1699850x559b9441381ap_PyEval_EvalCodeWithName+1498860x559b94414635p_PyFunction_FastCallDict+469870x559b94522b5bp880x559b9446b8fbp_PyObject_FastCallKeywords+1179890x559b944cee86p_PyEval_EvalFrameDefault+19094900x559b94462ccbp_PyFunction_FastCallKeywords+251910x559b944caa93p_PyEval_EvalFrameDefault+1699920x559b94413d09p_PyEval_EvalCodeWithName+2761930x559b94462f57p_PyFunction_FastCallKeywords+903940x559b944fe383p950x559b94434584p_PyMethodDef_RawFastCallDict+404960x559b944347c1p_PyCFunction_FastCallDict+33970x559b944d0007p_PyEval_EvalFrameDefault+23575980x559b94462ccbp_PyFunction_FastCallKeywords+251990x559b944caa93p_PyEval_EvalFrameDefault+1699
# 配置优化器(Optimizer Function) 随机梯度下降SGD 学习率为0.001# clone操作一定要在定义优化器之前进行!!! 否则也是会报错的。 sgd_optimezer=fluid.optimizer.SGD(learning_rate=0.1) # learning_rate为学习率sgd_optimezer.minimize(avg_loss)
clone操作一定要在定义优化器之前进行!!! 否则也是会报错的。 解决方法如下:
先配置优化器,再进行 clone 操作。