From a96cefd6b6e411b5168192173e3ea5e6b4c88eac Mon Sep 17 00:00:00 2001 From: rensilin Date: Mon, 19 Aug 2019 16:52:26 +0800 Subject: [PATCH] loss_function(*output) Change-Id: Iecc2518dc91b88125d29958ae78d5a8af3eb7eee --- .../train/custom_trainer/feed/scripts/create_programs.py | 6 +++--- paddle/fluid/train/custom_trainer/feed/scripts/example.py | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) 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 3c014683..e0021741 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 5cac7f42..96db068a 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) -- GitLab