Logging metrics that return dicts #15335
Unanswered
Aceticia
asked this question in
Lightning Trainer API: Trainer, LightningModule, LightningDataModule
Replies: 1 comment 2 replies
-
In fact, the best practice is to pass the metric object to class MyModel(LightningModule):
def __init__(self):
...
self.accuracy = torchmetrics.Accuracy()
def training_step(self, batch, batch_idx):
x, y = batch
preds = self(x)
...
# log step metric
self.accuracy(preds, y)
self.log('train_acc_step', self.accuracy)
...
def training_epoch_end(self, outs):
# log epoch metric
self.log('train_acc_epoch', self.accuracy) For more details, please refers to https://torchmetrics.readthedocs.io/en/stable/pages/lightning.html |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have a torchmetric class that calculates many different aspects of the predictions. More specifically, it returns a dict of
Dict[MetricName, float]
. It looks likeself.log
andself.log_dict
only take single output metrics? Is there a way of directly logging the torchmetric object?For now I'm just updating it, taking its return dict and call
self.log_dict
. Works, but not as cleanBeta Was this translation helpful? Give feedback.
All reactions