Skip to content

Commit fd80076

Browse files
committed
Merge remote-tracking branch 'upstream/main' into ch23
2 parents 2d6cca0 + 3093dec commit fd80076

20 files changed

+735
-116
lines changed

.github/contributing_templates/notebook/example_feature.ipynb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,6 @@
230230
"pygments_lexer": "ipython3",
231231
"version": "3.8.10 (default, Nov 14 2022, 12:59:47) \n[GCC 9.4.0]"
232232
},
233-
"orig_nbformat": 4,
234233
"vscode": {
235234
"interpreter": {
236235
"hash": "916dbcbb3f70747c44a77c7bcd40155683ae19c65e1c03b4aa3499c5328201f1"

2d_classification/monai_101.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,8 +345,7 @@
345345
"nbconvert_exporter": "python",
346346
"pygments_lexer": "ipython3",
347347
"version": "3.8.10"
348-
},
349-
"orig_nbformat": 4
348+
}
350349
},
351350
"nbformat": 4,
352351
"nbformat_minor": 2

3d_segmentation/swin_unetr_btcv_segmentation_3d.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@
523523
" val_outputs_list = decollate_batch(val_outputs)\n",
524524
" val_output_convert = [post_pred(val_pred_tensor) for val_pred_tensor in val_outputs_list]\n",
525525
" dice_metric(y_pred=val_output_convert, y=val_labels_convert)\n",
526-
" epoch_iterator_val.set_description(\"Validate (%d / %d Steps)\" % (global_step, 10.0))\n",
526+
" epoch_iterator_val.set_description(\"Validate (%d / %d Steps)\" % (global_step, 10.0)) # noqa: B038\n",
527527
" mean_dice_val = dice_metric.aggregate().item()\n",
528528
" dice_metric.reset()\n",
529529
" return mean_dice_val\n",
@@ -546,7 +546,9 @@
546546
" scaler.step(optimizer)\n",
547547
" scaler.update()\n",
548548
" optimizer.zero_grad()\n",
549-
" epoch_iterator.set_description(f\"Training ({global_step} / {max_iterations} Steps) (loss={loss:2.5f})\")\n",
549+
" epoch_iterator.set_description( # noqa: B038\n",
550+
" f\"Training ({global_step} / {max_iterations} Steps) (loss={loss:2.5f})\"\n",
551+
" )\n",
550552
" if (global_step % eval_num == 0 and global_step != 0) or global_step == max_iterations:\n",
551553
" epoch_iterator_val = tqdm(val_loader, desc=\"Validate (X / X Steps) (dice=X.X)\", dynamic_ncols=True)\n",
552554
" dice_val = validation(epoch_iterator_val)\n",

3d_segmentation/unetr_btcv_segmentation_3d.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@
621621
" val_outputs_list = decollate_batch(val_outputs)\n",
622622
" val_output_convert = [post_pred(val_pred_tensor) for val_pred_tensor in val_outputs_list]\n",
623623
" dice_metric(y_pred=val_output_convert, y=val_labels_convert)\n",
624-
" epoch_iterator_val.set_description(\"Validate (%d / %d Steps)\" % (global_step, 10.0))\n",
624+
" epoch_iterator_val.set_description(\"Validate (%d / %d Steps)\" % (global_step, 10.0)) # noqa: B038\n",
625625
" mean_dice_val = dice_metric.aggregate().item()\n",
626626
" dice_metric.reset()\n",
627627
" return mean_dice_val\n",
@@ -641,7 +641,9 @@
641641
" epoch_loss += loss.item()\n",
642642
" optimizer.step()\n",
643643
" optimizer.zero_grad()\n",
644-
" epoch_iterator.set_description(\"Training (%d / %d Steps) (loss=%2.5f)\" % (global_step, max_iterations, loss))\n",
644+
" epoch_iterator.set_description( # noqa: B038\n",
645+
" \"Training (%d / %d Steps) (loss=%2.5f)\" % (global_step, max_iterations, loss)\n",
646+
" )\n",
645647
" if (global_step % eval_num == 0 and global_step != 0) or global_step == max_iterations:\n",
646648
" epoch_iterator_val = tqdm(val_loader, desc=\"Validate (X / X Steps) (dice=X.X)\", dynamic_ncols=True)\n",
647649
" dice_val = validation(epoch_iterator_val)\n",

bundle/02_mednist_classification.ipynb

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,9 @@
265265
"cell_type": "code",
266266
"execution_count": 3,
267267
"id": "d11681af-3210-4b2b-b7bd-8ad8dedfe230",
268-
"metadata": {},
268+
"metadata": {
269+
"lines_to_next_cell": 2
270+
},
269271
"outputs": [
270272
{
271273
"name": "stdout",
@@ -310,8 +312,7 @@
310312
" - _target_: EnsureChannelFirstd\n",
311313
" keys: 'image'\n",
312314
" - _target_: ScaleIntensityd\n",
313-
" keys: 'image'\n",
314-
" "
315+
" keys: 'image'"
315316
]
316317
},
317318
{
@@ -369,19 +370,19 @@
369370
" num_workers: 4\n",
370371
"\n",
371372
"trainer:\n",
372-
" _target_: SupervisedTrainer\n",
373-
" device: '@device'\n",
374-
" max_epochs: '@max_epochs'\n",
375-
" train_data_loader: '@train_dl'\n",
376-
" network: '@net'\n",
377-
" optimizer: \n",
378-
" _target_: torch.optim.Adam\n",
379-
" params: '[email protected]()'\n",
380-
" lr: 0.00001 # learning rate set slow so that you can see network improvement over epochs\n",
381-
" loss_function: \n",
382-
" _target_: torch.nn.CrossEntropyLoss\n",
383-
" inferer: \n",
384-
" _target_: SimpleInferer\n",
373+
" _target_: SupervisedTrainer\n",
374+
" device: '@device'\n",
375+
" max_epochs: '@max_epochs'\n",
376+
" train_data_loader: '@train_dl'\n",
377+
" network: '@net'\n",
378+
" optimizer: \n",
379+
" _target_: torch.optim.Adam\n",
380+
" params: '[email protected]()'\n",
381+
" lr: 0.00001 # learning rate set slow so that you can see network improvement over epochs\n",
382+
" loss_function: \n",
383+
" _target_: torch.nn.CrossEntropyLoss\n",
384+
" inferer: \n",
385+
" _target_: SimpleInferer\n",
385386
"\n",
386387
"train:\n",
387388
"- '[email protected]()'\n",
@@ -527,8 +528,7 @@
527528
" prob = result.detach().to(\"cpu\")[0]\n",
528529
" pred = class_names[prob.argmax()]\n",
529530
" gt = item[\"class_name\"][0]\n",
530-
" print(f\"Prediction: {pred}. Ground-truth: {gt}\")\n",
531-
" "
531+
" print(f\"Prediction: {pred}. Ground-truth: {gt}\")\n"
532532
]
533533
},
534534
{
@@ -543,7 +543,9 @@
543543
"cell_type": "code",
544544
"execution_count": 9,
545545
"id": "b4e1f99a-a68b-4aeb-bcf2-842f26609b52",
546-
"metadata": {},
546+
"metadata": {
547+
"lines_to_next_cell": 2
548+
},
547549
"outputs": [
548550
{
549551
"name": "stdout",

bundle/03_mednist_classification_v2.ipynb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@
185185
"cell_type": "code",
186186
"execution_count": 4,
187187
"id": "0cb1b023-d192-4ad7-b2eb-c4a2c6b42b84",
188-
"metadata": {},
188+
"metadata": {
189+
"lines_to_next_cell": 2
190+
},
189191
"outputs": [
190192
{
191193
"name": "stdout",
@@ -233,7 +235,9 @@
233235
"cell_type": "code",
234236
"execution_count": 5,
235237
"id": "d11681af-3210-4b2b-b7bd-8ad8dedfe230",
236-
"metadata": {},
238+
"metadata": {
239+
"lines_to_next_cell": 2
240+
},
237241
"outputs": [
238242
{
239243
"name": "stdout",
@@ -287,8 +291,7 @@
287291
"- _target_: EnsureChannelFirstd\n",
288292
" keys: '@image'\n",
289293
"- _target_: ScaleIntensityd\n",
290-
" keys: '@image'\n",
291-
" "
294+
" keys: '@image'\n"
292295
]
293296
},
294297
{
@@ -306,7 +309,9 @@
306309
"cell_type": "code",
307310
"execution_count": 6,
308311
"id": "4dfd052e-abe7-473a-bbf4-25674a3b20ea",
309-
"metadata": {},
312+
"metadata": {
313+
"lines_to_next_cell": 2
314+
},
310315
"outputs": [
311316
{
312317
"name": "stdout",
@@ -322,7 +327,7 @@
322327
"max_epochs: 25\n",
323328
"learning_rate: 0.00001 # learning rate, again artificially slow\n",
324329
"val_interval: 1 # run validation every n'th epoch\n",
325-
"save_interval: 1 # save the model weights every n'th epoch\n",
330+
"save_interval: 1 # save the model weights every n'th epoch\n",
326331
"\n",
327332
"# choose a unique output subdirectory every time training is started, \n",
328333
"output_dir: '$datetime.datetime.now().strftime(@root_dir+''/output/output_%y%m%d_%H%M%S'')'\n",
@@ -429,7 +434,7 @@
429434
" output_transform: '$lambda x: None'\n",
430435
"- _target_: LogfileHandler\n",
431436
" output_dir: '@output_dir'\n",
432-
" \n",
437+
"\n",
433438
"# Metrics to assess validation results, you can have more than one here but may \n",
434439
"# need to adapt the format of pred and label.\n",
435440
"metrics:\n",

bundle/04_integrating_code.ipynb

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@
206206
"execution_count": 3,
207207
"id": "dcdbe1ae-ea13-49cb-b5a3-3c2c78f91f2b",
208208
"metadata": {
209+
"lines_to_next_cell": 2,
209210
"tags": []
210211
},
211212
"outputs": [
@@ -224,7 +225,6 @@
224225
"import torch.nn as nn\n",
225226
"import torch.nn.functional as F\n",
226227
"\n",
227-
"\n",
228228
"class Net(nn.Module):\n",
229229
" def __init__(self):\n",
230230
" super().__init__()\n",
@@ -257,7 +257,9 @@
257257
"cell_type": "code",
258258
"execution_count": 4,
259259
"id": "189d71c5-6556-4891-a382-0adbc8f80d30",
260-
"metadata": {},
260+
"metadata": {
261+
"lines_to_next_cell": 2
262+
},
261263
"outputs": [
262264
{
263265
"name": "stdout",
@@ -274,14 +276,15 @@
274276
"\n",
275277
"transform = transforms.Compose(\n",
276278
" [transforms.ToTensor(),\n",
277-
" transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])\n"
279+
" transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])"
278280
]
279281
},
280282
{
281283
"cell_type": "code",
282284
"execution_count": 5,
283285
"id": "3d8f233e-495c-450c-a445-46d295ba7461",
284286
"metadata": {
287+
"lines_to_next_cell": 2,
285288
"tags": []
286289
},
287290
"outputs": [
@@ -301,17 +304,18 @@
301304
"\n",
302305
"batch_size = 4\n",
303306
"\n",
307+
"\n",
304308
"def get_dataloader(is_training, transform):\n",
305-
" \n",
309+
"\n",
306310
" if is_training:\n",
307311
" trainset = torchvision.datasets.CIFAR10(root='./data', train=True,\n",
308-
" download=True, transform=transform)\n",
312+
" download=True, transform=transform)\n",
309313
" trainloader = torch.utils.data.DataLoader(trainset, batch_size=batch_size,\n",
310314
" shuffle=True, num_workers=2)\n",
311315
" return trainloader\n",
312316
" else:\n",
313317
" testset = torchvision.datasets.CIFAR10(root='./data', train=False,\n",
314-
" download=True, transform=transform)\n",
318+
" download=True, transform=transform)\n",
315319
" testloader = torch.utils.data.DataLoader(testset, batch_size=batch_size,\n",
316320
" shuffle=False, num_workers=2)\n",
317321
" return testloader "
@@ -347,8 +351,7 @@
347351
"import torch.nn as nn\n",
348352
"import torch.optim as optim\n",
349353
"\n",
350-
"\n",
351-
"def train(net,trainloader):\n",
354+
"def train(net, trainloader):\n",
352355
" criterion = nn.CrossEntropyLoss()\n",
353356
" optimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9)\n",
354357
"\n",
@@ -390,6 +393,7 @@
390393
"execution_count": 7,
391394
"id": "0b9764a8-674c-42ae-ad4b-f2dea027bdbf",
392395
"metadata": {
396+
"lines_to_next_cell": 2,
393397
"tags": []
394398
},
395399
"outputs": [
@@ -542,11 +546,10 @@
542546
"\n",
543547
"import torch\n",
544548
"\n",
545-
"\n",
546549
"def test(net, testloader):\n",
547550
" correct = 0\n",
548551
" total = 0\n",
549-
" \n",
552+
"\n",
550553
" with torch.no_grad():\n",
551554
" for data in testloader:\n",
552555
" images, labels = data\n",
@@ -555,15 +558,16 @@
555558
" total += labels.size(0)\n",
556559
" correct += (predicted == labels).sum().item()\n",
557560
"\n",
558-
" print(f'Accuracy of the network on the 10000 test images: {100 * correct // total} %')\n",
559-
" "
561+
" print(f'Accuracy of the network on the 10000 test images: {100 * correct // total} %')\n"
560562
]
561563
},
562564
{
563565
"cell_type": "code",
564566
"execution_count": 3,
565567
"id": "fb49aef2-9fb5-4e74-83d2-9da935e07648",
566-
"metadata": {},
568+
"metadata": {
569+
"lines_to_next_cell": 2
570+
},
567571
"outputs": [
568572
{
569573
"name": "stdout",
@@ -678,13 +682,12 @@
678682
"import torch\n",
679683
"from PIL import Image\n",
680684
"\n",
681-
"\n",
682685
"def inference(net, transforms, filenames):\n",
683686
" for fn in filenames:\n",
684687
" with Image.open(fn) as im:\n",
685688
" tim=transforms(im)\n",
686689
" outputs=net(tim[None])\n",
687-
" _, predictions = torch.max(outputs, 1)\n",
690+
" _, predictions=torch.max(outputs, 1)\n",
688691
" print(fn, predictions[0].item())"
689692
]
690693
},

bundle/05_spleen_segmentation_lightning.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,7 @@
11871187
"name": "python",
11881188
"nbconvert_exporter": "python",
11891189
"pygments_lexer": "ipython3",
1190-
"version": "3.9.18"
1190+
"version": "3.10.12"
11911191
}
11921192
},
11931193
"nbformat": 4,

computer_assisted_intervention/video_seg.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@
364364
" iou_list.append(epoch_iou)\n",
365365
" epoch_loss /= len(dl)\n",
366366
" losses.append(epoch_loss)\n",
367-
" tr.set_description(f\"Loss: {epoch_loss:.4f}\")\n",
367+
" tr.set_description(f\"Loss: {epoch_loss:.4f}\") # noqa: B038\n",
368368
"\n",
369369
"fig, ax = plt.subplots(1, 1, figsize=(6, 6), facecolor=\"white\")\n",
370370
"ax.set_xlabel(\"Epoch\")\n",

deployment/ray/mednist_classifier_ray.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,7 @@
368368
"\n",
369369
"ray.init(address=\"auto\", namespace=\"serve\")\n",
370370
"\n",
371+
"\n",
371372
"@serve.deployment\n",
372373
"class MedNISTClassifier:\n",
373374
" def __init__(self):\n",

0 commit comments

Comments
 (0)