Skip to content

Commit

Permalink
Improve logging in Colab
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Achard committed Dec 21, 2024
1 parent c201a0e commit c199b5f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
30 changes: 29 additions & 1 deletion napari_cellseg3d/dev_scripts/colab_training.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Script to run WNet training in Google Colab."""

import time
from pathlib import Path

Expand Down Expand Up @@ -55,7 +56,28 @@
)
WANDB_INSTALLED = False

# TODO subclass to reduce code duplication

class LogFixture:
"""Fixture for napari-less logging, replaces napari_cellseg3d.interface.Log in model_workers.
This allows to redirect the output of the workers to stdout instead of a specialized widget.
"""

def __init__(self):
"""Creates a LogFixture object."""
super(LogFixture, self).__init__()

def print_and_log(self, text, printing=None):
"""Prints and logs text."""
print(text)

def warn(self, warning):
"""Logs warning."""
logger.warning(warning)

def error(self, e):
"""Logs error."""
raise (e)


class WNetTrainingWorkerColab(TrainingWorkerBase):
Expand Down Expand Up @@ -728,8 +750,14 @@ def get_colab_worker(
worker_config (config.WNetTrainingWorkerConfig): config for the training worker
wandb_config (config.WandBConfig): config for wandb
"""
log = LogFixture()
worker = WNetTrainingWorkerColab(worker_config)
worker.wandb_config = wandb_config

worker.log_signal.connect(log.print_and_log)
worker.warn_signal.connect(log.warn)
worker.error_signal.connect(log.error)

return worker


Expand Down
2 changes: 1 addition & 1 deletion notebooks/Colab_WNet3D_training.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"id": "Ax-vJAWRwIKi"
},
"source": [
"## (optional) **1.3 Initialize Weights & Biases integration **\n",
"## Optional - *1.3 Initialize Weights & Biases integration*\n",
"---\n",
"If you wish to utilize Weights & Biases (WandB) for monitoring and logging your training session, uncomment and execute the cell below.\n",
"To enable it, just input your API key in the space provided."
Expand Down

0 comments on commit c199b5f

Please sign in to comment.