From aefa284a02bef6473dfa80aeb2b448b8f16adc27 Mon Sep 17 00:00:00 2001 From: fanqiNO1 <1848839264@qq.com> Date: Sat, 9 Nov 2024 19:14:22 +0800 Subject: [PATCH] [Fix] Fix val_loss when the output is not list --- mmengine/runner/loops.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mmengine/runner/loops.py b/mmengine/runner/loops.py index 5a678db7b9..822756ef25 100644 --- a/mmengine/runner/loops.py +++ b/mmengine/runner/loops.py @@ -403,7 +403,8 @@ def run_iter(self, idx, data_batch: Sequence[dict]): with autocast(enabled=self.fp16): outputs = self.runner.model.val_step(data_batch) - outputs, self.val_loss = _update_losses(outputs, self.val_loss) + if isinstance(outputs, list): + outputs, self.val_loss = _update_losses(outputs, self.val_loss) self.evaluator.process(data_samples=outputs, data_batch=data_batch) self.runner.call_hook( @@ -486,7 +487,8 @@ def run_iter(self, idx, data_batch: Sequence[dict]) -> None: with autocast(enabled=self.fp16): outputs = self.runner.model.test_step(data_batch) - outputs, self.test_loss = _update_losses(outputs, self.test_loss) + if isinstance(outputs, list): + outputs, self.test_loss = _update_losses(outputs, self.test_loss) self.evaluator.process(data_samples=outputs, data_batch=data_batch) self.runner.call_hook(