paddle如何获取参数梯度?
Ta的回复 :第一个问题已经解决 trainable_vars = list(filter(self.is_trainable, self.main_program.list_vars())) vars,grads = self.run_gradient(trainable_vars,X,y,self.keeps) for trainable_var,var,grad in zip(trainable_vars,vars,grads): print('\tdebug:%s'%trainable_var.name, '\tshape=',trainable_var.shape, '\tdata.mean=%.6f'%var.mean(), '\tgrad.mean=%.6f' % grad.mean(), '\tdata.std=%.6f'%var.std(), '\tgrad.std=%.6f'%grad.std()) def run_gradient(self,trainable_vars,X,y,keeps): vars_value = [] for var in trainable_vars : var_value = fluid.global_scope().find_var(var.name).get_tensor() vars_value.append(np.array(var_value)) grads = fluid.gradients(self.loss, trainable_vars) grads = self.executor.run(self.main_program,feed={self.X_input.name:X,self.t_input.name:y}, fetch_list=grads) return vars_value,grads