* format files

* remove best metric score callback

* update readme
This commit is contained in:
Łukasz Zalewski authored and GitHub committed 2021-03-15 17:24:56 +01:00
1 parent d571a4e2c2
commit 1f326bb5e9
7 files changed
+18 -69

No files matched your search

+2 -52
View File
@@ -26,7 +26,7 @@ def get_wandb_logger(trainer: pl.Trainer) -> WandbLogger:
class UploadCodeToWandbAsArtifact(Callback):
"""Upload all *.py files to wandb as an artifact at the beginning of the run."""
"""Upload all *.py files to wandb as an artifact, at the beginning of the run."""
def __init__(self, code_dir: str):
self.code_dir = code_dir
@@ -43,7 +43,7 @@ class UploadCodeToWandbAsArtifact(Callback):
class UploadCheckpointsToWandbAsArtifact(Callback):
"""Upload experiment checkpoints to wandb as an artifact at the end of training."""
"""Upload checkpoints to wandb as an artifact, at the end of training."""
def __init__(self, ckpt_dir: str = "checkpoints/", upload_best_only: bool = False):
self.ckpt_dir = ckpt_dir
@@ -82,7 +82,6 @@ class LogF1PrecisionRecallHeatmapToWandb(Callback):
"""
Generate f1, precision and recall heatmap from validation step outputs.
Expects validation step to return predictions and targets.
Works only for single label classification!
"""
def __init__(self, class_names: List[str] = None):
@@ -136,7 +135,6 @@ class LogConfusionMatrixToWandb(Callback):
"""
Generate Confusion Matrix.
Expects validation step to return predictions and targets.
Works only for single label classification!
"""
def __init__(self, class_names: List[str] = None):
@@ -180,51 +178,3 @@ class LogConfusionMatrixToWandb(Callback):
self.preds = []
self.targets = []
''' BUGGED :(
class LogBestMetricScoresToWandb(Callback):
"""
Store in wandb:
- max train acc
- min train loss
- max val acc
- min val loss
Useful for comparing runs in table views, as wandb doesn't currently support column aggregation.
"""
def __init__(self):
self.train_loss_best = None
self.train_acc_best = None
self.val_loss_best = None
self.val_acc_best = None
self.ready = False
def on_sanity_check_end(self, trainer, pl_module):
"""Start executing this callback only after all validation sanity checks end."""
self.ready = True
def on_epoch_end(self, trainer, pl_module):
if self.ready:
logger = get_wandb_logger(trainer=trainer)
experiment = logger.experiment
metrics = trainer.callback_metrics
if not self.train_loss_best or metrics["train/loss"] < self.train_loss_best:
self.train_loss_best = metrics["train_loss"]
if not self.train_acc_best or metrics["train/acc"] > self.train_acc_best:
self.train_acc_best = metrics["train/acc"]
if not self.val_loss_best or metrics["val/loss"] < self.val_loss_best:
self.val_loss_best = metrics["val/loss"]
if not self.val_acc_best or metrics["val/acc"] > self.val_acc_best:
self.val_acc_best = metrics["val/acc"]
experiment.log({"train/loss_best": self.train_loss_best}, commit=False)
experiment.log({"train/acc_best": self.train_acc_best}, commit=False)
experiment.log({"val/loss_best": self.val_loss_best}, commit=False)
experiment.log({"val/acc_best": self.val_acc_best}, commit=False)
'''