How to not throw errors with single-class batches #309
Answered
by
SkafteNicki
cmcmaster1
asked this question in
Q&A
-
Sorry for the very dumb thread, but I still cannot figure out how to only evaluate AUROC at the end of each epoch in PL, so it doesn't throw an error with small batches that do not contain both classes. |
Beta Was this translation helpful? Give feedback.
Answered by
SkafteNicki
Jun 29, 2021
Replies: 1 comment 1 reply
-
Hi @cmcmaster1, class MyModel(pl.LightningModule):
def __init__(self, ...):
super().__init__()
...
self.val_metric = torchmetrics.AUROC()
def validation_step(self, batch, batch_idx):
x, y = batch
yhat = model(x)
self.metric.update(yhat, y)
def validation_epoch_end(self, outputs):
auroc_val = self.metric.compute()
self.log("val_auroc", auroc_val) Hope this helps :] |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Borda
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @cmcmaster1,
Here is how you could do your validation loop:
Hope this helps :]