Skip to content

Commit

Permalink
Commit from GitHub Actions (Build Notebooks)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben-Salmon committed Aug 23, 2024
1 parent d7ee3d5 commit b6dfc93
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 43 deletions.
59 changes: 45 additions & 14 deletions 01_CARE/exercise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,6 @@
"metadata": {},
"outputs": [],
"source": [
"%load_ext tensorboard\n",
"\n",
"\n",
"import tifffile\n",
"import numpy as np\n",
"from pathlib import Path\n",
Expand Down Expand Up @@ -482,7 +479,6 @@
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
Expand Down Expand Up @@ -736,12 +732,37 @@
]
},
{
"cell_type": "code",
"execution_count": null,
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-info\"><h3>Task 3: Tensorboard</h3>\n",
"\n",
"We'll monitor the training of all models in 05_image_restoration using Tensorboard. \n",
"This is a program that plots the training and validation loss of networks as they train, and can also show input/output image pairs.\n",
"Follow these steps to launch Tensorboard.\n",
"\n",
"1) Open the extensions panel in VS Code. Look for this icon. \n",
"\n",
"![image](nb_data/extensions.png)\n",
"\n",
"2) Search Tensorboard and install and install the extension published by Microsoft.\n",
"3) Open the command palette (ctrl+shift+p), search for Python: Launch Tensorboard and hit enter.\n",
"4) When prompted, select either \"Use current working directory\" or \"Select another folder\" and enter the path to the `01_CARE/runs/` directory.\n",
"\n",
"Once it's open, continue to the next cell to start training, then open the Tensorboard tab to see the loss curves.\n",
"\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"outputs": [],
"source": [
"%tensorboard --logdir runs"
"In tensorboard, click the SCALARS tab to see the training and validation loss curves. \n",
"At the end of each epoch, refresh Tensorboard using the button in the top right to see the latest loss.\n",
"\n",
"Click the IMAGES tab to see the noisy inputs, denoised outputs and clean targets.\n",
"These are updated at the end of each epoch too."
]
},
{
Expand All @@ -757,6 +778,13 @@
"\n",
"# tensorboard\n",
"tb_logger = SummaryWriter(\"runs/Unet\"+datetime.now().strftime('%d%H-%M%S'))\n",
"def log_image(image, tag, logger, step):\n",
" normalised_image = image.cpu().numpy()\n",
" normalised_image = normalised_image - np.percentile(normalised_image, 1)\n",
" normalised_image = normalised_image / np.percentile(normalised_image, 99)\n",
" normalised_image = np.clip(normalised_image, 0, 1)\n",
" logger.add_images(tag=tag, img_tensor=normalised_image, global_step=step)\n",
"\n",
"\n",
"train_losses = []\n",
"val_losses = []\n",
Expand Down Expand Up @@ -793,11 +821,9 @@
" tb_logger.add_scalar(tag=\"val_loss\", scalar_value=val_loss, global_step=step)\n",
"\n",
" # we always log the last validation images\n",
" tb_logger.add_images(tag=\"val_input\", img_tensor=batch.to(\"cpu\"), global_step=step)\n",
" tb_logger.add_images(tag=\"val_target\", img_tensor=target.to(\"cpu\"), global_step=step)\n",
" tb_logger.add_images(\n",
" tag=\"val_prediction\", img_tensor=output.to(\"cpu\"), global_step=step\n",
" )\n",
" log_image(batch, tag=\"val_input\", logger=tb_logger, step=step)\n",
" log_image(target, tag=\"val_target\", logger=tb_logger, step=step)\n",
" log_image(output, tag=\"val_prediction\", logger=tb_logger, step=step)\n",
"\n",
" print(f\"Validation loss: {val_loss.item()}\")\n",
"\n",
Expand Down Expand Up @@ -888,7 +914,7 @@
"tags": []
},
"source": [
"<div class=\"alert alert-block alert-info\"><h3>Task 3: Predict using the correct mean/std</h3>\n",
"<div class=\"alert alert-block alert-info\"><h3>Task 4: Predict using the correct mean/std</h3>\n",
"\n",
"In Part 1 we normalized the inputs and the targets before feeding them into the model. This means that the model will output normalized clean images, but we'd like them to be on the same scale as the real clean images.\n",
"\n",
Expand Down Expand Up @@ -1001,6 +1027,11 @@
"This notebook has shown how matched pairs of noisy and clean images can train a UNet to denoise, but what if we don't have any clean images? In the next notebook, we'll try Noise2Void, a method for training a UNet to denoise with only noisy images.\n",
"</div>"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
Expand Down
15 changes: 13 additions & 2 deletions 02_Noise2Void/exercise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@
" patch_size=[64, 64],\n",
" batch_size=128,\n",
" num_epochs=10,\n",
" roi_size=3,\n",
" masked_pixel_percentage=0.05,\n",
" roi_size=11,\n",
" masked_pixel_percentage=0.2,\n",
" logger=\"tensorboard\"\n",
")"
]
Expand Down Expand Up @@ -428,6 +428,8 @@
"\n",
"Remember the configuration? Didn't we set `logger` to `tensorboard`? Then we can visualize the loss curve!\n",
"\n",
"Open Tensorboard in VS Code (check Task 3 in 01_CARE) to monitor training. \n",
"Logs for this model are stored in the `02_N2V/logs/` folder.\n",
"</div>\n",
"\n",
"<div class=\"alert alert-block alert-warning\"><h3>Question: N2V loss curve</h3>\n",
Expand Down Expand Up @@ -629,6 +631,15 @@
"ax[1].imshow(new_preds.squeeze(), cmap=\"gray\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"train_image[:128, :128].shape"
]
},
{
"attachments": {},
"cell_type": "markdown",
Expand Down
29 changes: 3 additions & 26 deletions 03_COSDD/exercise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -480,14 +480,9 @@
"\n",
"### Task 1.4.\n",
"\n",
"We're going to use Tensorboard to monitor training metrics. Run the two cells below to open tensorboard in the notebook. If it doesn't work, follow the steps below to open it in a browser.\n",
"\n",
"1. Open a terminal.\n",
"2. Enter `conda activate 05_image_restoration` to activate an environment with Tensorboard installed.\n",
"3. Enter `tensorboard --logdir 05_image_restoration/03_COSDD/checkpoints`\n",
"4. Finally, open a browser and enter localhost:6006 in the address bar.\n",
"\n",
"Once you're in tensorboard, you'll see the training logs of your model and the logs of a model that's already been trained for 3.5 hours.\n",
"Open Tensorboard (check Task 3 in 01_CARE) to monitor training.\n",
"This model is unlike the previous two because it has more than one loss curve.\n",
"The cell below describes how to interpret each one.\n",
"</div>"
]
},
Expand All @@ -511,24 +506,6 @@
"Note that the trainer is set to train for only 10 minutes in this example. Remove the line with `max_time` to train fully."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%load_ext tensorboard"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%tensorboard --logdir checkpoints/"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
2 changes: 1 addition & 1 deletion 04_DenoiSplit/exercise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,7 @@
},
{
"cell_type": "markdown",
"id": "dbecd052",
"id": "52159fdb",
"metadata": {},
"source": [
"<hr style=\"height:2px;\"><div class=\"alert alert-block alert-success\"><h1>End of the exercise</h1>\n",
Expand Down

0 comments on commit b6dfc93

Please sign in to comment.