format files

This commit is contained in:
ashleve committed 2021-04-26 14:32:25 +02:00
1 parent 36bd4c3f11
commit 5cc767a595
2 files changed
+17 -11

No files matched your search

+1 -1
View File
@@ -25,7 +25,7 @@ save_f1_precision_recall_heatmap_to_wandb:
save_confusion_matrix_to_wandb:
_target_: src.callbacks.wandb_callbacks.LogConfusionMatrixToWandb
log_images:
_target_: src.callbacks.wandb_callbacks.ImagePredictionLogger
num_samples: 8
+16 -10
View File
@@ -196,12 +196,12 @@ class LogF1PrecRecHeatmapToWandb(Callback):
self.preds.clear()
self.targets.clear()
class ImagePredictionLogger(Callback):
"""Logs a validation batch and their predictions to wandb.
Example adapted from:
https://wandb.ai/wandb/wandb-lightning/reports/Image-Classification-using-PyTorch-Lightning--VmlldzoyODk1NzY
Example adapted from:
https://wandb.ai/wandb/wandb-lightning/reports/Image-Classification-using-PyTorch-Lightning--VmlldzoyODk1NzY
"""
def __init__(self, num_samples: int = 8):
@@ -220,7 +220,7 @@ class ImagePredictionLogger(Callback):
if self.ready:
logger = get_wandb_logger(trainer=trainer)
experiment = logger.experiment
# get a validation batch from the validation dat loader
val_samples = next(iter(trainer.datamodule.val_dataloader()))
val_imgs, val_labels = val_samples
@@ -231,9 +231,15 @@ class ImagePredictionLogger(Callback):
preds = torch.argmax(logits, axis=-1)
# log the images as wandb Image
experiment.log({
f"Images/{experiment.name}":[wandb.Image(x, caption=f"Pred:{pred}, Label:{y}")
for x, pred, y in zip(val_imgs[:self.num_samples],
preds[:self.num_samples],
val_labels[:self.num_samples])]
})
experiment.log(
{
f"Images/{experiment.name}": [
wandb.Image(x, caption=f"Pred:{pred}, Label:{y}")
for x, pred, y in zip(
val_imgs[: self.num_samples],
preds[: self.num_samples],
val_labels[: self.num_samples],
)
]
}
)