* change local lambda to normal function and move it outside of main method to enable DDP

* update .pre-commit-config.yaml

* update requirements.txt

* reformat files

* remove disabling lightning logs feature

* change logging strings to enable python 3.7

* update README.md

* remove double logging bug prevention since lightning fixed that
This commit is contained in:
Łukasz Zalewski authored and GitHub committed 2021-03-30 03:19:32 +02:00
1 parent bc0de86874
commit 99b9c1a717
9 files changed
+146 -140

No files matched your search

+16 -23
View File
@@ -22,11 +22,22 @@ def get_wandb_logger(trainer: Trainer) -> WandbLogger:
return logger
raise Exception(
"You are using wandb related callback,"
"but WandbLogger was not found for some reason..."
"You are using wandb related callback, but WandbLogger was not found for some reason..."
)
class WatchModelWithWandb(Callback):
"""Make WandbLogger watch model at the beginning of the run."""
def __init__(self, log: str = "gradients", log_freq: int = 100):
self.log = log
self.log_freq = log_freq
def on_train_start(self, trainer, pl_module):
logger = get_wandb_logger(trainer=trainer)
logger.watch(model=trainer.model, log=self.log, log_freq=self.log_freq)
class UploadCodeToWandbAsArtifact(Callback):
"""Upload all *.py files to wandb as an artifact, at the beginning of the run."""
@@ -60,26 +71,12 @@ class UploadCheckpointsToWandbAsArtifact(Callback):
if self.upload_best_only:
ckpts.add_file(trainer.checkpoint_callback.best_model_path)
else:
for path in glob.glob(
os.path.join(self.ckpt_dir, "**/*.ckpt"), recursive=True
):
for path in glob.glob(os.path.join(self.ckpt_dir, "**/*.ckpt"), recursive=True):
ckpts.add_file(path)
experiment.use_artifact(ckpts)
class WatchModelWithWandb(Callback):
"""Make WandbLogger watch model at the beginning of the run."""
def __init__(self, log: str = "gradients", log_freq: int = 100):
self.log = log
self.log_freq = log_freq
def on_train_start(self, trainer, pl_module):
logger = get_wandb_logger(trainer=trainer)
logger.watch(model=trainer.model, log=self.log, log_freq=self.log_freq)
class LogConfusionMatrixToWandb(Callback):
"""Generate confusion matrix every epoch and send it to wandb.
Expects validation step to return predictions and targets.
@@ -126,9 +123,7 @@ class LogConfusionMatrixToWandb(Callback):
sn.heatmap(confusion_matrix, annot=True, annot_kws={"size": 8}, fmt="g")
# names should be uniqe or else charts from different experiments in wandb will overlap
experiment.log(
{f"confusion_matrix/{experiment.name}": wandb.Image(plt)}, commit=False
)
experiment.log({f"confusion_matrix/{experiment.name}": wandb.Image(plt)}, commit=False)
# according to wandb docs this should also work but it crashes
# experiment.log(f{"confusion_matrix/{experiment.name}": plt})
@@ -194,9 +189,7 @@ class LogF1PrecRecHeatmapToWandb(Callback):
)
# names should be uniqe or else charts from different experiments in wandb will overlap
experiment.log(
{f"f1_p_r_heatmap/{experiment.name}": wandb.Image(plt)}, commit=False
)
experiment.log({f"f1_p_r_heatmap/{experiment.name}": wandb.Image(plt)}, commit=False)
# reset plot
plt.clf()