def validation_step(self, batch, batch_idx, dataloader_idx=None):
I calculate metrci here.
metric = XXXX
def on_validation_epoch_end(self):
I would like to get the metric here .
I answered a similar question here: How to access the returned values of *_step()
The same answer applies to all *_epoch_end hooks, including validation.
Well, this means that I need to collect the information at validation_step
and then recalculate the metric at the on_validation_epoch_end
.
My intention is that I often log the metric at validation_step
, and it would be nice if the user could access the metric Lightning has calculated at on_validation_epoch_end
.
def validation_step(self, batch, batch_idx, dataloader_idx=None):
f1, precision, recall, acc, current_batch_size = self.share_val_step(batch)
metrics = {'val_acc': acc, 'val_f1': f1, 'val_precision': precision, 'val_recall': recall}
# log metric
self.log_dict(metrics, prog_bar=True, logger=True, on_epoch=True,
rank_zero_only=True, batch_size=current_batch_size)
def on_validation_epoch_end(self):
# Access to the metric Lightning has calculated