format files
This commit is contained in:
1 parent
36bd4c3f11
commit
5cc767a595
2 files changed
+17
-11
No files matched your search
@@ -25,7 +25,7 @@ save_f1_precision_recall_heatmap_to_wandb:
|
|||||||
|
|
||||||
save_confusion_matrix_to_wandb:
|
save_confusion_matrix_to_wandb:
|
||||||
_target_: src.callbacks.wandb_callbacks.LogConfusionMatrixToWandb
|
_target_: src.callbacks.wandb_callbacks.LogConfusionMatrixToWandb
|
||||||
|
|
||||||
log_images:
|
log_images:
|
||||||
_target_: src.callbacks.wandb_callbacks.ImagePredictionLogger
|
_target_: src.callbacks.wandb_callbacks.ImagePredictionLogger
|
||||||
num_samples: 8
|
num_samples: 8
|
||||||
@@ -196,12 +196,12 @@ class LogF1PrecRecHeatmapToWandb(Callback):
|
|||||||
|
|
||||||
self.preds.clear()
|
self.preds.clear()
|
||||||
self.targets.clear()
|
self.targets.clear()
|
||||||
|
|
||||||
|
|
||||||
class ImagePredictionLogger(Callback):
|
class ImagePredictionLogger(Callback):
|
||||||
"""Logs a validation batch and their predictions to wandb.
|
"""Logs a validation batch and their predictions to wandb.
|
||||||
Example adapted from:
|
Example adapted from:
|
||||||
https://wandb.ai/wandb/wandb-lightning/reports/Image-Classification-using-PyTorch-Lightning--VmlldzoyODk1NzY
|
https://wandb.ai/wandb/wandb-lightning/reports/Image-Classification-using-PyTorch-Lightning--VmlldzoyODk1NzY
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, num_samples: int = 8):
|
def __init__(self, num_samples: int = 8):
|
||||||
@@ -220,7 +220,7 @@ class ImagePredictionLogger(Callback):
|
|||||||
if self.ready:
|
if self.ready:
|
||||||
logger = get_wandb_logger(trainer=trainer)
|
logger = get_wandb_logger(trainer=trainer)
|
||||||
experiment = logger.experiment
|
experiment = logger.experiment
|
||||||
|
|
||||||
# get a validation batch from the validation dat loader
|
# get a validation batch from the validation dat loader
|
||||||
val_samples = next(iter(trainer.datamodule.val_dataloader()))
|
val_samples = next(iter(trainer.datamodule.val_dataloader()))
|
||||||
val_imgs, val_labels = val_samples
|
val_imgs, val_labels = val_samples
|
||||||
@@ -231,9 +231,15 @@ class ImagePredictionLogger(Callback):
|
|||||||
preds = torch.argmax(logits, axis=-1)
|
preds = torch.argmax(logits, axis=-1)
|
||||||
|
|
||||||
# log the images as wandb Image
|
# log the images as wandb Image
|
||||||
experiment.log({
|
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],
|
f"Images/{experiment.name}": [
|
||||||
preds[:self.num_samples],
|
wandb.Image(x, caption=f"Pred:{pred}, Label:{y}")
|
||||||
val_labels[:self.num_samples])]
|
for x, pred, y in zip(
|
||||||
})
|
val_imgs[: self.num_samples],
|
||||||
|
preds[: self.num_samples],
|
||||||
|
val_labels[: self.num_samples],
|
||||||
|
)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
)
|
||||||
Reference in new issue
Block a user