Skip to content

Commit 362354a

Browse files
author
Yuchen Xu
committed
updated for 0.9.1rc2 compatibility
1 parent 2978120 commit 362354a

File tree

5 files changed

+45
-164
lines changed

5 files changed

+45
-164
lines changed

acceleration/automatic_mixed_precision.ipynb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@
8888
" RandCropByPosNegLabeld,\n",
8989
" ScaleIntensityRanged,\n",
9090
" Spacingd,\n",
91-
" EnsureTyped,\n",
92-
" EnsureType,\n",
9391
")\n",
9492
"from monai.utils import get_torch_version_tuple, set_determinism\n",
9593
"from torch.utils.data import DataLoader\n",

acceleration/dataset_type_performance.ipynb

Lines changed: 10 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -49,42 +49,11 @@
4949
},
5050
{
5151
"cell_type": "code",
52-
"execution_count": 1,
52+
"execution_count": null,
5353
"metadata": {
5454
"tags": []
5555
},
56-
"outputs": [
57-
{
58-
"name": "stdout",
59-
"output_type": "stream",
60-
"text": [
61-
"MONAI version: 0.6.0rc1+15.gf3d436a0\n",
62-
"Numpy version: 1.20.3\n",
63-
"Pytorch version: 1.9.0a0+c3d40fd\n",
64-
"MONAI flags: HAS_EXT = True, USE_COMPILED = False\n",
65-
"MONAI rev id: f3d436a09deefcf905ece2faeec37f55ab030003\n",
66-
"\n",
67-
"Optional dependencies:\n",
68-
"Pytorch Ignite version: 0.4.5\n",
69-
"Nibabel version: 3.2.1\n",
70-
"scikit-image version: 0.15.0\n",
71-
"Pillow version: 8.2.0\n",
72-
"Tensorboard version: 2.5.0\n",
73-
"gdown version: 3.13.0\n",
74-
"TorchVision version: 0.10.0a0\n",
75-
"ITK version: 5.1.2\n",
76-
"tqdm version: 4.53.0\n",
77-
"lmdb version: 1.2.1\n",
78-
"psutil version: 5.8.0\n",
79-
"pandas version: 1.1.4\n",
80-
"einops version: 0.3.0\n",
81-
"\n",
82-
"For details about installing the optional dependencies, please visit:\n",
83-
" https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies\n",
84-
"\n"
85-
]
86-
}
87-
],
56+
"outputs": [],
8857
"source": [
8958
"# Copyright 2020 MONAI Consortium\n",
9059
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
@@ -130,8 +99,6 @@
13099
" RandCropByPosNegLabeld,\n",
131100
" ScaleIntensityRanged,\n",
132101
" Spacingd,\n",
133-
" EnsureTyped,\n",
134-
" EnsureType,\n",
135102
")\n",
136103
"from monai.utils import set_determinism\n",
137104
"\n",
@@ -151,19 +118,11 @@
151118
},
152119
{
153120
"cell_type": "code",
154-
"execution_count": 2,
121+
"execution_count": null,
155122
"metadata": {
156123
"tags": []
157124
},
158-
"outputs": [
159-
{
160-
"name": "stdout",
161-
"output_type": "stream",
162-
"text": [
163-
"/workspace/data/medical\n"
164-
]
165-
}
166-
],
125+
"outputs": [],
167126
"source": [
168127
"directory = os.environ.get(\"MONAI_DATA_DIRECTORY\")\n",
169128
"root_dir = tempfile.mkdtemp() if directory is None else directory\n",
@@ -209,8 +168,8 @@
209168
" loss_function = DiceLoss(to_onehot_y=True, softmax=True)\n",
210169
" optimizer = torch.optim.Adam(model.parameters(), 1e-4)\n",
211170
"\n",
212-
" post_pred = Compose([EnsureType(), AsDiscrete(argmax=True, to_onehot=2)])\n",
213-
" post_label = Compose([EnsureType(), AsDiscrete(to_onehot=2)])\n",
171+
" post_pred = Compose([AsDiscrete(argmax=True, to_onehot=2)])\n",
172+
" post_label = Compose([AsDiscrete(to_onehot=2)])\n",
214173
"\n",
215174
" dice_metric = DiceMetric(include_background=True, reduction=\"mean\", get_not_nans=False)\n",
216175
"\n",
@@ -264,8 +223,8 @@
264223
" val_outputs = sliding_window_inference(\n",
265224
" val_inputs, roi_size, sw_batch_size, model\n",
266225
" )\n",
267-
" val_outputs = [post_pred(i) for i in decollate_batch(val_outputs)]\n",
268-
" val_labels = [post_label(i) for i in decollate_batch(val_labels)]\n",
226+
" val_outputs = [post_pred(i) for i in decollate_batch(val_outputs.as_tensor())]\n",
227+
" val_labels = [post_label(i) for i in decollate_batch(val_labels.as_tensor())]\n",
269228
" dice_metric(y_pred=val_outputs, y=val_labels)\n",
270229
"\n",
271230
" metric = dice_metric.aggregate().item()\n",
@@ -381,7 +340,6 @@
381340
"\n",
382341
"Non-deterministic transforms:\n",
383342
"* RandCropByPosNegLabeld\n",
384-
"* EnsureTyped\n",
385343
"\n",
386344
"All the validation transforms are deterministic.\n",
387345
"The results of all the deterministic transforms will be cached to accelerate training."
@@ -427,7 +385,6 @@
427385
" image_key=\"image\",\n",
428386
" image_threshold=0,\n",
429387
" ),\n",
430-
" EnsureTyped(keys=[\"image\", \"label\"]),\n",
431388
" ]\n",
432389
" )\n",
433390
"\n",
@@ -452,7 +409,6 @@
452409
" clip=True,\n",
453410
" ),\n",
454411
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
455-
" EnsureTyped(keys=[\"image\", \"label\"]),\n",
456412
" ]\n",
457413
" )\n",
458414
" return train_transforms, val_transforms"
@@ -739,7 +695,7 @@
739695
],
740696
"metadata": {
741697
"kernelspec": {
742-
"display_name": "Python 3",
698+
"display_name": "Python 3 (ipykernel)",
743699
"language": "python",
744700
"name": "python3"
745701
},
@@ -753,7 +709,7 @@
753709
"name": "python",
754710
"nbconvert_exporter": "python",
755711
"pygments_lexer": "ipython3",
756-
"version": "3.7.10"
712+
"version": "3.8.13"
757713
}
758714
},
759715
"nbformat": 4,

acceleration/fast_training_tutorial.ipynb

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
},
4646
{
4747
"cell_type": "code",
48-
"execution_count": 1,
48+
"execution_count": null,
4949
"metadata": {
5050
"vscode": {
5151
"languageId": "python"
@@ -126,8 +126,6 @@
126126
" ScaleIntensityRanged,\n",
127127
" Spacingd,\n",
128128
" ToDeviced,\n",
129-
" EnsureTyped,\n",
130-
" EnsureType,\n",
131129
")\n",
132130
"from monai.utils import set_determinism\n",
133131
"\n",
@@ -180,7 +178,7 @@
180178
},
181179
{
182180
"cell_type": "code",
183-
"execution_count": 4,
181+
"execution_count": null,
184182
"metadata": {
185183
"vscode": {
186184
"languageId": "python"
@@ -234,7 +232,7 @@
234232
},
235233
{
236234
"cell_type": "code",
237-
"execution_count": 5,
235+
"execution_count": null,
238236
"metadata": {
239237
"vscode": {
240238
"languageId": "python"
@@ -298,7 +296,7 @@
298296
},
299297
{
300298
"cell_type": "code",
301-
"execution_count": 19,
299+
"execution_count": null,
302300
"metadata": {
303301
"vscode": {
304302
"languageId": "python"
@@ -328,7 +326,7 @@
328326
},
329327
{
330328
"cell_type": "code",
331-
"execution_count": 8,
329+
"execution_count": null,
332330
"metadata": {
333331
"vscode": {
334332
"languageId": "python"
@@ -364,8 +362,6 @@
364362
" bg_postfix=\"_bg\",\n",
365363
" image_key=\"image\",\n",
366364
" )),\n",
367-
" # change to execute transforms with Tensor data\n",
368-
" range_func(\"EnsureType\", EnsureTyped(keys=[\"image\", \"label\"])),\n",
369365
" ]\n",
370366
"\n",
371367
" if fast:\n",
@@ -407,7 +403,6 @@
407403
" clip=True,\n",
408404
" ),\n",
409405
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
410-
" EnsureTyped(keys=[\"image\", \"label\"]),\n",
411406
" ]\n",
412407
" if fast:\n",
413408
" # move the data to GPU and cache to avoid CPU -> GPU sync in every epoch\n",
@@ -438,7 +433,7 @@
438433
},
439434
{
440435
"cell_type": "code",
441-
"execution_count": 16,
436+
"execution_count": null,
442437
"metadata": {
443438
"vscode": {
444439
"languageId": "python"
@@ -518,8 +513,8 @@
518513
" norm=Norm.BATCH,\n",
519514
" ).to(device)\n",
520515
"\n",
521-
" post_pred = Compose([EnsureType(), AsDiscrete(argmax=True, to_onehot=2)])\n",
522-
" post_label = Compose([EnsureType(), AsDiscrete(to_onehot=2)])\n",
516+
" post_pred = Compose([AsDiscrete(argmax=True, to_onehot=2)])\n",
517+
" post_label = Compose([AsDiscrete(to_onehot=2)])\n",
523518
"\n",
524519
" dice_metric = DiceMetric(include_background=False, reduction=\"mean\", get_not_nans=False)\n",
525520
"\n",
@@ -614,7 +609,7 @@
614609
" with torch.no_grad():\n",
615610
" val_loader_iterator = iter(val_loader)\n",
616611
"\n",
617-
" for val_step in range(len(val_loader)):\n",
612+
" for _ in range(len(val_loader)):\n",
618613
" # profiling: val dataload\n",
619614
" with nvtx.annotate(\"dataload\", color=\"red\") if profiling else no_profiling:\n",
620615
" val_data = next(val_loader_iterator)\n",
@@ -641,8 +636,8 @@
641636
"\n",
642637
" # profiling: decollate batch\n",
643638
" with nvtx.annotate(\"decollate batch\", color=\"blue\") if profiling else no_profiling:\n",
644-
" val_outputs = [post_pred(i) for i in decollate_batch(val_outputs)]\n",
645-
" val_labels = [post_label(i) for i in decollate_batch(val_labels)]\n",
639+
" val_outputs = [post_pred(i) for i in decollate_batch(val_outputs.as_tensor())]\n",
640+
" val_labels = [post_label(i) for i in decollate_batch(val_labels.as_tensor())]\n",
646641
"\n",
647642
" # profiling: compute metric\n",
648643
" with nvtx.annotate(\"compute metric\", color=\"yellow\") if profiling else no_profiling:\n",
@@ -1020,7 +1015,7 @@
10201015
},
10211016
{
10221017
"cell_type": "code",
1023-
"execution_count": 15,
1018+
"execution_count": null,
10241019
"metadata": {
10251020
"vscode": {
10261021
"languageId": "python"

acceleration/threadbuffer_performance.ipynb

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"source": [
2020
"## Setup Environment\n",
2121
"\n",
22-
"The current MONAI main branch must be installed for this feature (as of release 0.3.0), skip this step if already installed:"
22+
"The current MONAI main branch must be installed for this feature (as of release 0.9.1), skip this step if already installed:"
2323
]
2424
},
2525
{
@@ -33,46 +33,17 @@
3333
},
3434
{
3535
"cell_type": "code",
36-
"execution_count": 1,
36+
"execution_count": null,
3737
"metadata": {},
38-
"outputs": [
39-
{
40-
"name": "stdout",
41-
"output_type": "stream",
42-
"text": [
43-
"MONAI version: 0.4.0\n",
44-
"Numpy version: 1.19.1\n",
45-
"Pytorch version: 1.7.0a0+7036e91\n",
46-
"MONAI flags: HAS_EXT = False, USE_COMPILED = False\n",
47-
"MONAI rev id: 0563a4467fa602feca92d91c7f47261868d171a1\n",
48-
"\n",
49-
"Optional dependencies:\n",
50-
"Pytorch Ignite version: 0.4.2\n",
51-
"Nibabel version: 3.2.1\n",
52-
"scikit-image version: 0.15.0\n",
53-
"Pillow version: 8.0.1\n",
54-
"Tensorboard version: 2.2.0\n",
55-
"gdown version: 3.12.2\n",
56-
"TorchVision version: 0.8.0a0\n",
57-
"ITK version: 5.1.2\n",
58-
"tqdm version: 4.54.1\n",
59-
"lmdb version: 1.0.0\n",
60-
"psutil version: 5.7.2\n",
61-
"\n",
62-
"For details about installing the optional dependencies, please visit:\n",
63-
" https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies\n",
64-
"\n"
65-
]
66-
}
67-
],
38+
"outputs": [],
6839
"source": [
6940
"import monai\n",
7041
"import numpy as np\n",
7142
"import torch\n",
7243
"from monai.data import DataLoader, Dataset, ThreadBuffer, create_test_image_2d\n",
7344
"from monai.losses import Dice\n",
7445
"from monai.networks.nets import UNet\n",
75-
"from monai.transforms import AddChanneld, Compose, MapTransform, EnsureTyped\n",
46+
"from monai.transforms import AddChanneld, Compose, MapTransform\n",
7647
"\n",
7748
"monai.utils.set_determinism(seed=0)\n",
7849
"\n",
@@ -88,7 +59,7 @@
8859
},
8960
{
9061
"cell_type": "code",
91-
"execution_count": 2,
62+
"execution_count": null,
9263
"metadata": {},
9364
"outputs": [],
9465
"source": [
@@ -111,7 +82,6 @@
11182
" [\n",
11283
" RandomGenerator(keys=(\"im\", \"seg\")),\n",
11384
" AddChanneld(keys=(\"im\", \"seg\")),\n",
114-
" EnsureTyped(keys=(\"im\", \"seg\")),\n",
11585
" ]\n",
11686
")\n",
11787
"\n",
@@ -128,7 +98,7 @@
12898
},
12999
{
130100
"cell_type": "code",
131-
"execution_count": 3,
101+
"execution_count": null,
132102
"metadata": {},
133103
"outputs": [],
134104
"source": [
@@ -148,7 +118,7 @@
148118
},
149119
{
150120
"cell_type": "code",
151-
"execution_count": 4,
121+
"execution_count": null,
152122
"metadata": {},
153123
"outputs": [],
154124
"source": [
@@ -181,7 +151,9 @@
181151
{
182152
"cell_type": "code",
183153
"execution_count": 5,
184-
"metadata": {},
154+
"metadata": {
155+
"scrolled": true
156+
},
185157
"outputs": [
186158
{
187159
"name": "stdout",
@@ -265,7 +237,7 @@
265237
"name": "python",
266238
"nbconvert_exporter": "python",
267239
"pygments_lexer": "ipython3",
268-
"version": "3.8.12"
240+
"version": "3.8.13"
269241
}
270242
},
271243
"nbformat": 4,

0 commit comments

Comments
 (0)