Skip to content

Commit 7403995

Browse files
Update notebooks to match format requirements (#1160)
### Description This PR updated several tutorials to match the format requirements of contribution guideline. - [x] module tutorials - [x] pathology - [x] microscopy/multichannel_microscopy_classification.ipynb - [x] full_gpu_inference_pipeline/client/non_ensemble/client.ipynb - [x] federated_learning/openfl/openfl_mednist_2d_registration/workspace/Monai_MedNIST.ipynb - [x] deployment ### Checks <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Avoid including large-size files in the PR. - [x] Clean up long text outputs from code cells in the notebook. - [x] For security purposes, please check the contents and remove any sensitive info such as user names and private key. - [x] Ensure (1) hyperlinks and markdown anchors are working (2) use relative paths for tutorial repo files (3) put figure and graphs in the `./figure` folder - [x] Notebook runs automatically `./runner.sh -t <path to .ipynb file>` Signed-off-by: KumoLiu <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent d023a36 commit 7403995

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1522
-1635
lines changed

deployment/Triton/client/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020 - 2021 MONAI Consortium
1+
# Copyright (c) MONAI Consortium
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at

deployment/Triton/client/client_mednist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020 - 2021 MONAI Consortium
1+
# Copyright (c) MONAI Consortium
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at

deployment/Triton/models/mednist_class/1/model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Copyright (c) MONAI Consortium
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS,
8+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
# See the License for the specific language governing permissions and
10+
# limitations under the License.
11+
112
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
213
#
314
# Redistribution and use in source and binary forms, with or without

deployment/Triton/models/monai_covid/1/model.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1+
# Copyright (c) MONAI Consortium
2+
# Licensed under the Apache License, Version 2.0 (the "License");
3+
# you may not use this file except in compliance with the License.
4+
# You may obtain a copy of the License at
5+
# http://www.apache.org/licenses/LICENSE-2.0
6+
# Unless required by applicable law or agreed to in writing, software
7+
# distributed under the License is distributed on an "AS IS" BASIS,
8+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9+
# See the License for the specific language governing permissions and
10+
# limitations under the License.
11+
112
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
213
#
314
# Redistribution and use in source and binary forms, with or without

deployment/bentoml/mednist_classifier_bentoml.ipynb

Lines changed: 106 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
{
22
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"Copyright (c) MONAI Consortium \n",
8+
"Licensed under the Apache License, Version 2.0 (the \"License\"); \n",
9+
"you may not use this file except in compliance with the License. \n",
10+
"You may obtain a copy of the License at \n",
11+
"&nbsp;&nbsp;&nbsp;&nbsp;http://www.apache.org/licenses/LICENSE-2.0 \n",
12+
"Unless required by applicable law or agreed to in writing, software \n",
13+
"distributed under the License is distributed on an \"AS IS\" BASIS, \n",
14+
"WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. \n",
15+
"See the License for the specific language governing permissions and \n",
16+
"limitations under the License."
17+
]
18+
},
319
{
420
"cell_type": "markdown",
521
"metadata": {},
@@ -18,8 +34,10 @@
1834
},
1935
{
2036
"cell_type": "code",
21-
"execution_count": 1,
22-
"metadata": {},
37+
"execution_count": null,
38+
"metadata": {
39+
"scrolled": true
40+
},
2341
"outputs": [],
2442
"source": [
2543
"!python -c \"import monai\" || pip install -q \"monai-weekly[pillow, tqdm]\"\n",
@@ -44,24 +62,29 @@
4462
"name": "stdout",
4563
"output_type": "stream",
4664
"text": [
47-
"MONAI version: 0.4.0+119.g9898a89\n",
48-
"Numpy version: 1.19.2\n",
49-
"Pytorch version: 1.7.1\n",
50-
"MONAI flags: HAS_EXT = False, USE_COMPILED = False\n",
51-
"MONAI rev id: 9898a89d24364a9be3525d066a7492adf00b9e6b\n",
65+
"MONAI version: 1.1.0+11.g7de6c336.dirty\n",
66+
"Numpy version: 1.22.2\n",
67+
"Pytorch version: 1.13.0+cu117\n",
68+
"MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False\n",
69+
"MONAI rev id: 7de6c33656a99087ca3b89a817b0879cf093febc\n",
70+
"MONAI __file__: /workspace/Code/MONAI/monai/__init__.py\n",
5271
"\n",
5372
"Optional dependencies:\n",
54-
"Pytorch Ignite version: 0.4.2\n",
55-
"Nibabel version: 3.2.1\n",
56-
"scikit-image version: 0.18.1\n",
57-
"Pillow version: 8.1.0\n",
58-
"Tensorboard version: 2.4.1\n",
59-
"gdown version: 3.12.2\n",
60-
"TorchVision version: 0.8.2\n",
61-
"ITK version: 5.1.2\n",
62-
"tqdm version: 4.56.0\n",
63-
"lmdb version: 1.0.0\n",
64-
"psutil version: 5.8.0\n",
73+
"Pytorch Ignite version: 0.4.10\n",
74+
"Nibabel version: 4.0.2\n",
75+
"scikit-image version: 0.19.3\n",
76+
"Pillow version: 9.0.1\n",
77+
"Tensorboard version: 2.11.0\n",
78+
"gdown version: 4.6.0\n",
79+
"TorchVision version: 0.14.0+cu117\n",
80+
"tqdm version: 4.64.1\n",
81+
"lmdb version: 1.3.0\n",
82+
"psutil version: 5.9.2\n",
83+
"pandas version: 1.1.5\n",
84+
"einops version: 0.6.0\n",
85+
"transformers version: 4.21.3\n",
86+
"mlflow version: 2.0.1\n",
87+
"pynrrd version: 1.0.0\n",
6588
"\n",
6689
"For details about installing the optional dependencies, please visit:\n",
6790
" https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies\n",
@@ -70,17 +93,6 @@
7093
}
7194
],
7295
"source": [
73-
"# Copyright 2020 MONAI Consortium\n",
74-
"# Licensed under the Apache License, Version 2.0 (the \"License\");\n",
75-
"# you may not use this file except in compliance with the License.\n",
76-
"# You may obtain a copy of the License at\n",
77-
"# http://www.apache.org/licenses/LICENSE-2.0\n",
78-
"# Unless required by applicable law or agreed to in writing, software\n",
79-
"# distributed under the License is distributed on an \"AS IS\" BASIS,\n",
80-
"# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n",
81-
"# See the License for the specific language governing permissions and\n",
82-
"# limitations under the License.\n",
83-
"\n",
8496
"import os\n",
8597
"import shutil\n",
8698
"import tempfile\n",
@@ -96,7 +108,7 @@
96108
"from monai.networks.nets import DenseNet121\n",
97109
"from monai.engines import SupervisedTrainer\n",
98110
"from monai.transforms import (\n",
99-
" AddChannel,\n",
111+
" EnsureChannelFirst,\n",
100112
" Compose,\n",
101113
" LoadImage,\n",
102114
" RandFlip,\n",
@@ -112,6 +124,35 @@
112124
"print_config()"
113125
]
114126
},
127+
{
128+
"cell_type": "markdown",
129+
"metadata": {},
130+
"source": [
131+
"## Setup data directory\n",
132+
"You can specify a directory with the MONAI_DATA_DIRECTORY environment variable.\n",
133+
"This allows you to save results and reuse downloads.\n",
134+
"If not specified a temporary directory will be used."
135+
]
136+
},
137+
{
138+
"cell_type": "code",
139+
"execution_count": 2,
140+
"metadata": {},
141+
"outputs": [
142+
{
143+
"name": "stdout",
144+
"output_type": "stream",
145+
"text": [
146+
"/workspace/Data\n"
147+
]
148+
}
149+
],
150+
"source": [
151+
"directory = os.environ.get(\"MONAI_DATA_DIRECTORY\")\n",
152+
"root_dir = tempfile.mkdtemp() if directory is None else directory\n",
153+
"print(root_dir)"
154+
]
155+
},
115156
{
116157
"cell_type": "markdown",
117158
"metadata": {},
@@ -130,48 +171,12 @@
130171
},
131172
{
132173
"cell_type": "code",
133-
"execution_count": 2,
174+
"execution_count": 3,
134175
"metadata": {
135176
"tags": []
136177
},
137-
"outputs": [
138-
{
139-
"name": "stderr",
140-
"output_type": "stream",
141-
"text": [
142-
"MedNIST.tar.gz: 0.00B [00:00, ?B/s]"
143-
]
144-
},
145-
{
146-
"name": "stdout",
147-
"output_type": "stream",
148-
"text": [
149-
"/tmp/tmpxxp5z205\n"
150-
]
151-
},
152-
{
153-
"name": "stderr",
154-
"output_type": "stream",
155-
"text": [
156-
"MedNIST.tar.gz: 59.0MB [00:04, 15.4MB/s] \n"
157-
]
158-
},
159-
{
160-
"name": "stdout",
161-
"output_type": "stream",
162-
"text": [
163-
"\n",
164-
"downloaded file: /tmp/tmpxxp5z205/MedNIST.tar.gz.\n",
165-
"Verified 'MedNIST.tar.gz', md5: 0bc7306e7427e00ad1c5526a6677552d.\n",
166-
"Verified 'MedNIST.tar.gz', md5: 0bc7306e7427e00ad1c5526a6677552d.\n"
167-
]
168-
}
169-
],
178+
"outputs": [],
170179
"source": [
171-
"directory = os.environ.get(\"MONAI_DATA_DIRECTORY\")\n",
172-
"root_dir = tempfile.mkdtemp() if directory is None else directory\n",
173-
"print(root_dir)\n",
174-
"\n",
175180
"resource = \"https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/MedNIST.tar.gz\"\n",
176181
"md5 = \"0bc7306e7427e00ad1c5526a6677552d\"\n",
177182
"\n",
@@ -183,7 +188,7 @@
183188
},
184189
{
185190
"cell_type": "code",
186-
"execution_count": 3,
191+
"execution_count": 4,
187192
"metadata": {},
188193
"outputs": [
189194
{
@@ -224,14 +229,14 @@
224229
},
225230
{
226231
"cell_type": "code",
227-
"execution_count": 4,
232+
"execution_count": 5,
228233
"metadata": {},
229234
"outputs": [],
230235
"source": [
231236
"train_transforms = Compose(\n",
232237
" [\n",
233238
" LoadImage(image_only=True),\n",
234-
" AddChannel(),\n",
239+
" EnsureChannelFirst(),\n",
235240
" ScaleIntensity(),\n",
236241
" RandRotate(range_x=np.pi / 12, prob=0.5, keep_size=True),\n",
237242
" RandFlip(spatial_axis=0, prob=0.5),\n",
@@ -243,7 +248,7 @@
243248
},
244249
{
245250
"cell_type": "code",
246-
"execution_count": 5,
251+
"execution_count": 6,
247252
"metadata": {},
248253
"outputs": [],
249254
"source": [
@@ -267,8 +272,10 @@
267272
},
268273
{
269274
"cell_type": "code",
270-
"execution_count": 6,
271-
"metadata": {},
275+
"execution_count": 7,
276+
"metadata": {
277+
"scrolled": true
278+
},
272279
"outputs": [],
273280
"source": [
274281
"device = torch.device(\"cuda:0\")\n",
@@ -280,18 +287,27 @@
280287
},
281288
{
282289
"cell_type": "code",
283-
"execution_count": 7,
284-
"metadata": {},
290+
"execution_count": 8,
291+
"metadata": {
292+
"scrolled": false
293+
},
285294
"outputs": [
286295
{
287296
"name": "stdout",
288297
"output_type": "stream",
289298
"text": [
290-
"Epoch 1/5 Loss: 0.231450617313385\n",
291-
"Epoch 2/5 Loss: 0.07256477326154709\n",
292-
"Epoch 3/5 Loss: 0.04309789836406708\n",
293-
"Epoch 4/5 Loss: 0.04549304023385048\n",
294-
"Epoch 5/5 Loss: 0.025731785222887993\n"
299+
"2023-01-13 07:55:59,514 - Engine run resuming from iteration 0, epoch 0 until 5 epochs\n",
300+
"Epoch 1/5 Loss: 0.19491052627563477\n",
301+
"2023-01-13 07:56:20,118 - Epoch[1] Complete. Time taken: 00:00:20.343\n",
302+
"Epoch 2/5 Loss: 0.11047982424497604\n",
303+
"2023-01-13 07:56:39,910 - Epoch[2] Complete. Time taken: 00:00:19.792\n",
304+
"Epoch 3/5 Loss: 0.023833362385630608\n",
305+
"2023-01-13 07:56:59,798 - Epoch[3] Complete. Time taken: 00:00:19.887\n",
306+
"Epoch 4/5 Loss: 0.02349323034286499\n",
307+
"2023-01-13 07:57:19,839 - Epoch[4] Complete. Time taken: 00:00:20.041\n",
308+
"Epoch 5/5 Loss: 0.01211395114660263\n",
309+
"2023-01-13 07:57:39,858 - Epoch[5] Complete. Time taken: 00:00:20.018\n",
310+
"2023-01-13 07:57:39,859 - Engine run complete. Time taken: 00:01:40.344\n"
295311
]
296312
}
297313
],
@@ -608,6 +624,14 @@
608624
"!docker image ls"
609625
]
610626
},
627+
{
628+
"cell_type": "markdown",
629+
"metadata": {},
630+
"source": [
631+
"## Cleanup data directory\n",
632+
"Remove directory if a temporary was used."
633+
]
634+
},
611635
{
612636
"cell_type": "code",
613637
"execution_count": null,
@@ -635,7 +659,7 @@
635659
"name": "python",
636660
"nbconvert_exporter": "python",
637661
"pygments_lexer": "ipython3",
638-
"version": "3.7.10"
662+
"version": "3.8.13"
639663
}
640664
},
641665
"nbformat": 4,

0 commit comments

Comments
 (0)