Release/1.1 (#174)

* introduce different running modes: default, debug, experiment
* fix pytorch installation in setup_conda.sh
* fix incorrect calculation of precision, recall and f1 score in wandb callback
* add `_self_` to config.yaml for compatibility with hydra1.1
* fix setting seed in `train.py` so it's skipped when `seed=null`
* add exception message when trying to use wandb callbacks with `trainer.fast_dev_run=true`
* change `axis=-1` to `dim=-1` in LogImagePredictions callback
* add 'Reproducibilty' section to README.md
This commit is contained in:
Łukasz Zalewski authored and GitHub committed 2021-09-28 20:07:40 +02:00
1 parent 89b502b090
commit 86f30fb320
19 files changed
+131 -81

No files matched your search

+9 -4
View File
@@ -16,6 +16,11 @@ from sklearn.metrics import f1_score, precision_score, recall_score
def get_wandb_logger(trainer: Trainer) -> WandbLogger:
"""Safely get Weights&Biases logger from Trainer."""
if trainer.fast_dev_run:
raise Exception(
"Cannot use wandb callbacks since pytorch lightning disables loggers in `fast_dev_run=true` mode."
)
if isinstance(trainer.logger, WandbLogger):
return trainer.logger
@@ -207,9 +212,9 @@ class LogF1PrecRecHeatmap(Callback):
preds = torch.cat(self.preds).cpu().numpy()
targets = torch.cat(self.targets).cpu().numpy()
f1 = f1_score(preds, targets, average=None)
r = recall_score(preds, targets, average=None)
p = precision_score(preds, targets, average=None)
f1 = f1_score(targets, preds, average=None)
r = recall_score(targets, preds, average=None)
p = precision_score(targets, preds, average=None)
data = [f1, p, r]
# set figure size
@@ -267,7 +272,7 @@ class LogImagePredictions(Callback):
# run the batch through the network
val_imgs = val_imgs.to(device=pl_module.device)
logits = pl_module(val_imgs)
preds = torch.argmax(logits, axis=-1)
preds = torch.argmax(logits, dim=-1)
# log the images as wandb Image
experiment.log(
+1 -1
View File
@@ -28,7 +28,7 @@ def train(config: DictConfig) -> Optional[float]:
"""
# Set seed for random number generators in pytorch, numpy and python.random
if "seed" in config:
if config.get("seed"):
seed_everything(config.seed, workers=True)
# Init lightning datamodule
+7 -2
View File
@@ -46,10 +46,13 @@ def extras(config: DictConfig) -> None:
log.info("Disabling python warnings! <config.ignore_warnings=True>")
warnings.filterwarnings("ignore")
# set <config.trainer.fast_dev_run=True> if <config.debug=True>
# if <config.debug=True>
if config.get("debug"):
log.info("Running in debug mode! <config.debug=True>")
config.trainer.fast_dev_run = True
# if <config.name=...>
if config.get("name"):
log.info("Running in experiment mode! Name: {}".format(config.name))
# force debugger friendly configuration if <config.trainer.fast_dev_run=True>
if config.trainer.get("fast_dev_run"):
@@ -75,7 +78,9 @@ def print_config(
"datamodule",
"callbacks",
"logger",
"test_after_training",
"seed",
"name",
),
resolve: bool = True,
) -> None: