diff --git a/paddle/fluid/train/custom_trainer/feed/scripts/create_programs.py b/paddle/fluid/train/custom_trainer/feed/scripts/create_programs.py index 3c014683e92684195e8c0340a29558eea72606a4..e0021741eae73b1f14aa4894e78c0b3cef219633 100644 --- a/paddle/fluid/train/custom_trainer/feed/scripts/create_programs.py +++ b/paddle/fluid/train/custom_trainer/feed/scripts/create_programs.py @@ -30,10 +30,10 @@ class ModelBuilder: list: outputs pass - def _loss_function(outputs): + def _loss_function(*outputs): **This function is declared in the network_desc_path file, and will be set in initialize()** Args: - outputs: the second result of inference() + *outputs: the second result of inference() Returns: Variable: loss @@ -97,7 +97,7 @@ class ModelBuilder: with fluid.program_guard(main_program, startup_program): inputs, outputs = self._inference() test_program = main_program.clone(for_test=True) - loss, labels = self._loss_function(outputs) + loss, labels = self._loss_function(*outputs) optimizer = fluid.optimizer.SGD(learning_rate=1.0) params_grads = optimizer.backward(loss) diff --git a/paddle/fluid/train/custom_trainer/feed/scripts/example.py b/paddle/fluid/train/custom_trainer/feed/scripts/example.py index 5cac7f427fcd97c3cc7dd6b32af9abb0c82cbf95..96db068ab58f4bdb8b5f46c88bc34039d333f81e 100644 --- a/paddle/fluid/train/custom_trainer/feed/scripts/example.py +++ b/paddle/fluid/train/custom_trainer/feed/scripts/example.py @@ -32,10 +32,10 @@ def inference(): ctr_output = fluid.layers.fc(net, 1, act='sigmoid', name='ctr') return [cvm_input], [ctr_output] -def loss_function(outputs): +def loss_function(ctr_output): """ Args: - outputs: the second result of inference() + *outputs: the second result of inference() Returns: Variable: loss @@ -43,7 +43,6 @@ def loss_function(outputs): list: labels """ # TODO: calc loss here - ctr_output, = outputs label = fluid.layers.data(name='label_ctr', shape=ctr_output.shape, dtype='float32') loss = fluid.layers.square_error_cost(input=ctr_output, label=label)