From eb87ace6bbe3f79595e4705636bfe4c4e2a510fe Mon Sep 17 00:00:00 2001 From: zhangyajie Date: Sat, 25 Sep 2021 10:34:15 +0800 Subject: [PATCH] [Fix] Fix loss parse in val_step --- mmseg/models/segmentors/base.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mmseg/models/segmentors/base.py b/mmseg/models/segmentors/base.py index 906c6fe564..944da0f2e4 100644 --- a/mmseg/models/segmentors/base.py +++ b/mmseg/models/segmentors/base.py @@ -145,15 +145,22 @@ def train_step(self, data_batch, optimizer, **kwargs): return outputs - def val_step(self, data_batch, **kwargs): + def val_step(self, data_batch, optimizer=None, **kwargs): """The iteration step during validation. This method shares the same signature as :func:`train_step`, but used during val epochs. Note that the evaluation after training epochs is not implemented with this method, but an evaluation hook. """ - output = self(**data_batch, **kwargs) - return output + losses = self(**data_batch) + loss, log_vars = self._parse_losses(losses) + + outputs = dict( + loss=loss, + log_vars=log_vars, + num_samples=len(data_batch['img_metas'])) + + return outputs @staticmethod def _parse_losses(losses):