Skip to content

Commit

Permalink
Update bundle related notebook (#1508)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
KumoLiu and pre-commit-ci[bot] committed Sep 7, 2023
1 parent 799f40b commit 0c17b1d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 46 deletions.
45 changes: 27 additions & 18 deletions bundle/pythonic_usage_guidance/pythonic_bundle_access.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 4,
"metadata": {},
"outputs": [
{
Expand All @@ -159,18 +159,18 @@
"url None\n",
"remove_prefix monai_\n",
"progress True\n",
"2023-09-06 08:44:11,165 - INFO - --- input summary of monai.bundle.scripts.download ---\n",
"2023-09-06 08:44:11,167 - INFO - > name: 'spleen_ct_segmentation'\n",
"2023-09-06 08:44:11,167 - INFO - > bundle_dir: '/workspace/Data'\n",
"2023-09-06 08:44:11,167 - INFO - > source: 'github'\n",
"2023-09-06 08:44:11,167 - INFO - > remove_prefix: 'monai_'\n",
"2023-09-06 08:44:11,168 - INFO - > progress: True\n",
"2023-09-06 08:44:11,168 - INFO - ---\n",
"2023-09-07 12:19:11,083 - INFO - --- input summary of monai.bundle.scripts.download ---\n",
"2023-09-07 12:19:11,086 - INFO - > name: 'spleen_ct_segmentation'\n",
"2023-09-07 12:19:11,088 - INFO - > bundle_dir: '/workspace/Data'\n",
"2023-09-07 12:19:11,089 - INFO - > source: 'github'\n",
"2023-09-07 12:19:11,090 - INFO - > remove_prefix: 'monai_'\n",
"2023-09-07 12:19:11,091 - INFO - > progress: True\n",
"2023-09-07 12:19:11,092 - INFO - ---\n",
"\n",
"\n",
"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",
"2023-09-06 08:44:12,165 - INFO - File exists: /workspace/Data/spleen_ct_segmentation_v0.5.3.zip, skipped downloading.\n",
"2023-09-06 08:44:12,166 - INFO - Writing into directory: /workspace/Data.\n"
"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",
"2023-09-07 12:19:11,992 - INFO - File exists: /workspace/Data/spleen_ct_segmentation_v0.5.3.zip, skipped downloading.\n",
"2023-09-07 12:19:11,994 - INFO - Writing into directory: /workspace/Data.\n"
]
}
],
Expand Down Expand Up @@ -198,13 +198,13 @@
"workflow_name None\n",
"config_file /workspace/Data/spleen_ct_segmentation/configs/train.json\n",
"workflow_type train\n",
"2023-09-06 09:18:47,393 - INFO - --- input summary of monai.bundle.scripts.run ---\n",
"2023-09-06 09:18:47,395 - INFO - > config_file: '/workspace/Data/spleen_ct_segmentation/configs/train.json'\n",
"2023-09-06 09:18:47,396 - INFO - > workflow_type: 'train'\n",
"2023-09-06 09:18:47,397 - INFO - ---\n",
"2023-09-07 12:19:14,769 - INFO - --- input summary of monai.bundle.scripts.run ---\n",
"2023-09-07 12:19:14,772 - INFO - > config_file: '/workspace/Data/spleen_ct_segmentation/configs/train.json'\n",
"2023-09-07 12:19:14,775 - INFO - > workflow_type: 'train'\n",
"2023-09-07 12:19:14,776 - INFO - ---\n",
"\n",
"\n",
"2023-09-06 09:18:47,397 - INFO - Setting logging properties based on config: /workspace/Data/spleen_ct_segmentation/configs/logging.conf.\n"
"2023-09-07 12:19:14,778 - INFO - Setting logging properties based on config: /workspace/Data/spleen_ct_segmentation/configs/logging.conf.\n"
]
}
],
Expand Down Expand Up @@ -395,18 +395,27 @@
"metadata": {},
"outputs": [],
"source": [
"# Here we specify `return_state_dict=False` to return an instantiated model only for compatibility, will remove after MONAI v1.5.\n",
"# directly get an instantiated network that loaded the weights.\n",
"model = load(name=\"brats_mri_segmentation\", bundle_dir=root_dir, source=\"monaihosting\")\n",
"model = load(name=\"brats_mri_segmentation\", bundle_dir=root_dir, source=\"monaihosting\", return_state_dict=False)\n",
"\n",
"# directly update the parameters for the model from the bundle.\n",
"model = load(name=\"brats_mri_segmentation\", bundle_dir=root_dir, source=\"monaihosting\", in_channels=3, out_channels=1)\n",
"model = load(\n",
" name=\"brats_mri_segmentation\",\n",
" bundle_dir=root_dir,\n",
" source=\"monaihosting\",\n",
" in_channels=3,\n",
" out_channels=1,\n",
" return_state_dict=False,\n",
")\n",
"\n",
"# using `exclude_vars` to filter loading weights.\n",
"model = load(\n",
" name=\"brats_mri_segmentation\",\n",
" bundle_dir=root_dir,\n",
" source=\"monaihosting\",\n",
" copy_model_args={\"exclude_vars\": \"convInit|conv_final\"},\n",
" return_state_dict=False,\n",
")\n",
"\n",
"# pass model and return an instantiated network that loaded the weights.\n",
Expand Down
Loading

0 comments on commit 0c17b1d

Please sign in to comment.