From abd10e24a8457752d2e441fdbaa4934b5762f3e7 Mon Sep 17 00:00:00 2001 From: yh Date: Tue, 15 Oct 2019 10:47:16 +0800 Subject: [PATCH] =?UTF-8?q?1.=20=E4=BF=AE=E5=A4=8DTester=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E8=BF=87=E7=A8=8B=E4=B8=AD=E5=87=BA=E7=8E=B0=E5=BC=82=E5=B8=B8?= =?UTF-8?q?model=E4=B8=8D=E8=83=BD=E9=87=8D=E7=BD=AE=E4=B8=BATraining?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=9A=84bug;=202.=20FitlogCallback,=20Evalua?= =?UTF-8?q?teCallback=E5=9C=A8=E9=81=AD=E9=81=87exception=E6=97=B6?= =?UTF-8?q?=E7=9B=B4=E6=8E=A5raise=EF=BC=8C=E9=98=B2=E6=AD=A2=E5=87=BA?= =?UTF-8?q?=E7=8E=B0metric=E6=B2=A1=E6=9C=89=E9=87=8D=E6=96=B0=E5=BD=92?= =?UTF-8?q?=E9=9B=B6=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- fastNLP/core/callback.py | 9 +++++---- fastNLP/core/tester.py | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/fastNLP/core/callback.py b/fastNLP/core/callback.py index ad417340..095ebc3d 100644 --- a/fastNLP/core/callback.py +++ b/fastNLP/core/callback.py @@ -592,9 +592,10 @@ class FitlogCallback(Callback): fitlog.add_metric(eval_result, name=key, step=self.step, epoch=self.epoch) if better_result: fitlog.add_best_metric(eval_result, name=key) - except Exception: + except Exception as e: self.pbar.write("Exception happens when evaluate on DataSet named `{}`.".format(key)) - + raise e + def on_train_end(self): fitlog.finish() @@ -660,9 +661,9 @@ class EvaluateCallback(Callback): eval_result = tester.test() self.logger.info("EvaluateCallback evaluation on {}:".format(key)) self.logger.info(tester._format_eval_results(eval_result)) - except Exception: + except Exception as e: self.logger.error("Exception happens when evaluate on DataSet named `{}`.".format(key)) - + raise e class LRScheduler(Callback): """ diff --git a/fastNLP/core/tester.py b/fastNLP/core/tester.py index e92eb422..8e2ac8a7 100644 --- a/fastNLP/core/tester.py +++ b/fastNLP/core/tester.py @@ -189,10 +189,10 @@ class Tester(object): _check_loss_evaluate(prev_func_signature=prev_func_signature, func_signature=e.func_signature, check_res=e.check_res, pred_dict=pred_dict, target_dict=batch_y, dataset=self.data, check_level=0) - + finally: + self._mode(network, is_test=False) if self.verbose >= 1: logger.info("[tester] \n{}".format(self._format_eval_results(eval_results))) - self._mode(network, is_test=False) return eval_results def _mode(self, model, is_test=False):