Skip to content

Commit 0c17b1d

Browse files
Update bundle related notebook (#1508)
Fixes # . ### Description After avoiding the breaking changes in the `load` API in Project-MONAI/MONAI#6950, may need to update the bundle-related notebooks in this [PR](#1504). Mainly added `return_state_dict=False` to avoid return state_dict by default, will remove it after 1.5. ### 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 799f40b commit 0c17b1d

File tree

2 files changed

+68
-46
lines changed

2 files changed

+68
-46
lines changed

bundle/pythonic_usage_guidance/pythonic_bundle_access.ipynb

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
},
145145
{
146146
"cell_type": "code",
147-
"execution_count": 7,
147+
"execution_count": 4,
148148
"metadata": {},
149149
"outputs": [
150150
{
@@ -159,18 +159,18 @@
159159
"url None\n",
160160
"remove_prefix monai_\n",
161161
"progress True\n",
162-
"2023-09-06 08:44:11,165 - INFO - --- input summary of monai.bundle.scripts.download ---\n",
163-
"2023-09-06 08:44:11,167 - INFO - > name: 'spleen_ct_segmentation'\n",
164-
"2023-09-06 08:44:11,167 - INFO - > bundle_dir: '/workspace/Data'\n",
165-
"2023-09-06 08:44:11,167 - INFO - > source: 'github'\n",
166-
"2023-09-06 08:44:11,167 - INFO - > remove_prefix: 'monai_'\n",
167-
"2023-09-06 08:44:11,168 - INFO - > progress: True\n",
168-
"2023-09-06 08:44:11,168 - INFO - ---\n",
162+
"2023-09-07 12:19:11,083 - INFO - --- input summary of monai.bundle.scripts.download ---\n",
163+
"2023-09-07 12:19:11,086 - INFO - > name: 'spleen_ct_segmentation'\n",
164+
"2023-09-07 12:19:11,088 - INFO - > bundle_dir: '/workspace/Data'\n",
165+
"2023-09-07 12:19:11,089 - INFO - > source: 'github'\n",
166+
"2023-09-07 12:19:11,090 - INFO - > remove_prefix: 'monai_'\n",
167+
"2023-09-07 12:19:11,091 - INFO - > progress: True\n",
168+
"2023-09-07 12:19:11,092 - INFO - ---\n",
169169
"\n",
170170
"\n",
171-
"2023-09-06 08:44:12,165 - INFO - Expected md5 is None, skip md5 check for file /workspace/Data/spleen_ct_segmentation_v0.5.3.zip.\n",
172-
"2023-09-06 08:44:12,165 - INFO - File exists: /workspace/Data/spleen_ct_segmentation_v0.5.3.zip, skipped downloading.\n",
173-
"2023-09-06 08:44:12,166 - INFO - Writing into directory: /workspace/Data.\n"
171+
"2023-09-07 12:19:11,991 - INFO - Expected md5 is None, skip md5 check for file /workspace/Data/spleen_ct_segmentation_v0.5.3.zip.\n",
172+
"2023-09-07 12:19:11,992 - INFO - File exists: /workspace/Data/spleen_ct_segmentation_v0.5.3.zip, skipped downloading.\n",
173+
"2023-09-07 12:19:11,994 - INFO - Writing into directory: /workspace/Data.\n"
174174
]
175175
}
176176
],
@@ -198,13 +198,13 @@
198198
"workflow_name None\n",
199199
"config_file /workspace/Data/spleen_ct_segmentation/configs/train.json\n",
200200
"workflow_type train\n",
201-
"2023-09-06 09:18:47,393 - INFO - --- input summary of monai.bundle.scripts.run ---\n",
202-
"2023-09-06 09:18:47,395 - INFO - > config_file: '/workspace/Data/spleen_ct_segmentation/configs/train.json'\n",
203-
"2023-09-06 09:18:47,396 - INFO - > workflow_type: 'train'\n",
204-
"2023-09-06 09:18:47,397 - INFO - ---\n",
201+
"2023-09-07 12:19:14,769 - INFO - --- input summary of monai.bundle.scripts.run ---\n",
202+
"2023-09-07 12:19:14,772 - INFO - > config_file: '/workspace/Data/spleen_ct_segmentation/configs/train.json'\n",
203+
"2023-09-07 12:19:14,775 - INFO - > workflow_type: 'train'\n",
204+
"2023-09-07 12:19:14,776 - INFO - ---\n",
205205
"\n",
206206
"\n",
207-
"2023-09-06 09:18:47,397 - INFO - Setting logging properties based on config: /workspace/Data/spleen_ct_segmentation/configs/logging.conf.\n"
207+
"2023-09-07 12:19:14,778 - INFO - Setting logging properties based on config: /workspace/Data/spleen_ct_segmentation/configs/logging.conf.\n"
208208
]
209209
}
210210
],
@@ -395,18 +395,27 @@
395395
"metadata": {},
396396
"outputs": [],
397397
"source": [
398+
"# Here we specify `return_state_dict=False` to return an instantiated model only for compatibility, will remove after MONAI v1.5.\n",
398399
"# directly get an instantiated network that loaded the weights.\n",
399-
"model = load(name=\"brats_mri_segmentation\", bundle_dir=root_dir, source=\"monaihosting\")\n",
400+
"model = load(name=\"brats_mri_segmentation\", bundle_dir=root_dir, source=\"monaihosting\", return_state_dict=False)\n",
400401
"\n",
401402
"# directly update the parameters for the model from the bundle.\n",
402-
"model = load(name=\"brats_mri_segmentation\", bundle_dir=root_dir, source=\"monaihosting\", in_channels=3, out_channels=1)\n",
403+
"model = load(\n",
404+
" name=\"brats_mri_segmentation\",\n",
405+
" bundle_dir=root_dir,\n",
406+
" source=\"monaihosting\",\n",
407+
" in_channels=3,\n",
408+
" out_channels=1,\n",
409+
" return_state_dict=False,\n",
410+
")\n",
403411
"\n",
404412
"# using `exclude_vars` to filter loading weights.\n",
405413
"model = load(\n",
406414
" name=\"brats_mri_segmentation\",\n",
407415
" bundle_dir=root_dir,\n",
408416
" source=\"monaihosting\",\n",
409417
" copy_model_args={\"exclude_vars\": \"convInit|conv_final\"},\n",
418+
" return_state_dict=False,\n",
410419
")\n",
411420
"\n",
412421
"# pass model and return an instantiated network that loaded the weights.\n",

0 commit comments

Comments
 (0)