MCPcopy
hub / github.com/ashleve/lightning-hydra-template / validation_step

Method validation_step

src/models/mnist_module.py:138–151  ·  view source on GitHub ↗

Perform a single validation step on a batch of data from the validation set. :param batch: A batch of data (a tuple) containing the input tensor of images and target labels. :param batch_idx: The index of the current batch.

(self, batch: Tuple[torch.Tensor, torch.Tensor], batch_idx: int)

Source from the content-addressed store, hash-verified

136 pass
137
138 def validation_step(self, batch: Tuple[torch.Tensor, torch.Tensor], batch_idx: int) -> None:
139 """Perform a single validation step on a batch of data from the validation set.
140
141 :param batch: A batch of data (a tuple) containing the input tensor of images and target
142 labels.
143 :param batch_idx: The index of the current batch.
144 """
145 loss, preds, targets = self.model_step(batch)
146
147 # update and log metrics
148 self.val_loss(loss)
149 self.val_acc(preds, targets)
150 self.log("val/loss", self.val_loss, on_step=False, on_epoch=True, prog_bar=True)
151 self.log("val/acc", self.val_acc, on_step=False, on_epoch=True, prog_bar=True)
152
153 def on_validation_epoch_end(self) -> None:
154 "Lightning hook that is called when a validation epoch ends."

Callers

nothing calls this directly

Calls 1

model_stepMethod · 0.95

Tested by

no test coverage detected