Skip to content

Commit 4f72fb2

Browse files
committed
Ensure ./runner.sh passess all tessts
1 parent 3dda461 commit 4f72fb2

File tree

1 file changed

+14
-26
lines changed

1 file changed

+14
-26
lines changed

2d_regression/image_restoration.ipynb

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
},
7979
{
8080
"cell_type": "code",
81-
"execution_count": 69,
81+
"execution_count": null,
8282
"metadata": {
8383
"colab": {
8484
"base_uri": "https://localhost:8080/"
@@ -94,28 +94,23 @@
9494
" Compose,\n",
9595
" LoadImageD,\n",
9696
" ScaleIntensityd,\n",
97-
" RandGaussianNoiseD, \n",
98-
" RandGaussianSmoothD, \n",
99-
" RandAdjustContrastD, \n",
97+
" RandGaussianNoiseD,\n",
98+
" RandGaussianSmoothD,\n",
10099
")\n",
101-
"import numpy as np\n",
102100
"from monai.data import DataLoader, Dataset, CacheDataset\n",
103101
"from monai.config import print_config\n",
104102
"from monai.networks.nets.restormer import Restormer\n",
105103
"from monai.apps import MedNISTDataset\n",
106104
"\n",
107-
"import numpy as np\n",
108105
"import torch\n",
109106
"from monai.losses import SSIMLoss\n",
110107
"import matplotlib.pyplot as plt\n",
111108
"import os\n",
112109
"import tempfile\n",
113110
"\n",
114-
"from tqdm.notebook import tqdm\n",
115-
"\n",
116111
"\n",
117-
"#print_config()\n",
118-
"#set_determinism(42)"
112+
"print_config()\n",
113+
"set_determinism(42)"
119114
]
120115
},
121116
{
@@ -361,7 +356,7 @@
361356
},
362357
{
363358
"cell_type": "code",
364-
"execution_count": 70,
359+
"execution_count": null,
365360
"metadata": {
366361
"id": "zHAj8nuHXG-D",
367362
"outputId": "462d37f3-b59e-4d88-ca18-60224f69076d"
@@ -374,7 +369,7 @@
374369
" device = torch.device(\"mps\")\n",
375370
"else:\n",
376371
" device = torch.device(\"cpu\")\n",
377-
" \n",
372+
"\n",
378373
"model = Restormer(\n",
379374
" spatial_dims=2,\n",
380375
" in_channels=1,\n",
@@ -399,7 +394,7 @@
399394
},
400395
{
401396
"cell_type": "code",
402-
"execution_count": 72,
397+
"execution_count": null,
403398
"metadata": {
404399
"id": "eyiL4ccmYsjt"
405400
},
@@ -432,7 +427,7 @@
432427
}
433428
],
434429
"source": [
435-
"max_epochs = 20\n",
430+
"max_epochs = 2\n",
436431
"epoch_loss_values = []\n",
437432
"\n",
438433
"\n",
@@ -448,7 +443,7 @@
448443
" moving = batch_data[\"moving_hand\"].to(device)\n",
449444
" fixed = batch_data[\"fixed_hand\"].to(device)\n",
450445
" pred_image = model(moving)\n",
451-
" pred_image=torch.sigmoid(pred_image)\n",
446+
" pred_image = torch.sigmoid(pred_image)\n",
452447
"\n",
453448
" loss = image_loss(input=pred_image, target=fixed)\n",
454449
" loss.backward()\n",
@@ -514,7 +509,7 @@
514509
},
515510
{
516511
"cell_type": "code",
517-
"execution_count": 76,
512+
"execution_count": null,
518513
"metadata": {
519514
"colab": {
520515
"base_uri": "https://localhost:8080/"
@@ -534,16 +529,16 @@
534529
"source": [
535530
"val_ds = CacheDataset(data=training_datadict[2000:2500], transform=train_transforms, cache_rate=1.0, num_workers=0)\n",
536531
"val_loader = DataLoader(val_ds, batch_size=16, num_workers=0)\n",
537-
"model.eval() # Set model to evaluation mode\n",
532+
"model.eval() # Set model to evaluation mode\n",
538533
"\n",
539-
"with torch.no_grad(): # Disable gradient calculation for inference\n",
534+
"with torch.no_grad(): # Disable gradient calculation for inference\n",
540535
" for batch_data in val_loader:\n",
541536
" moving = batch_data[\"moving_hand\"].to(device)\n",
542537
" fixed = batch_data[\"fixed_hand\"].to(device)\n",
543538
" # Pass only the moving image, consistent with training\n",
544539
" pred_image = model(moving)\n",
545540
" pred_image = torch.sigmoid(pred_image)\n",
546-
" break # Process only the first batch for visualization\n",
541+
" break # Process only the first batch for visualization\n",
547542
"\n",
548543
"fixed_image = fixed.detach().cpu().numpy()[:, 0]\n",
549544
"moving_image = moving.detach().cpu().numpy()[:, 0]\n",
@@ -596,13 +591,6 @@
596591
"plt.axis(\"off\")\n",
597592
"plt.show()"
598593
]
599-
},
600-
{
601-
"cell_type": "code",
602-
"execution_count": null,
603-
"metadata": {},
604-
"outputs": [],
605-
"source": []
606594
}
607595
],
608596
"metadata": {

0 commit comments

Comments
 (0)