def test_step_end(self, outputs): self.log("test_loss", outputs["loss"], on_step=True, on_epoch=True) self.log( "test_iou", self.iou(outputs["preds"], outputs["target"]), ) self.log( "test_dice", dice_score(outputs["preds"], outputs["target"]), )
def validation_step(self, batch, batch_nb): x, y = batch['image'], batch['mask'] y_hat = self.net(x) loss = F.cross_entropy(y_hat, y) if self.n_classes > 1 else \ F.binary_cross_entropy_with_logits(y_hat, y) dice_acc = dice_score(y_hat, y) # logs metrics for each training_step, # and the average across the epoch, to the progress bar and logger self.log("val_acc", dice_acc, on_step=True, on_epoch=True, prog_bar=True, logger=True) tensorboard_logs = {'train_loss': loss, "train_acc": dice_acc} return {'val_loss': loss, 'log': tensorboard_logs}
def test_dice_score(pred, target, expected): score = dice_score(tensor(pred), tensor(target)) assert score == expected