Skip to content

Commit 3dfe68f

Browse files
Add weight downloading in swinunetr_finetune notebook (#1390)
Fixes #1389 . ### Description - Download weights in the notebook ### 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 - [ ] Notebook runs automatically `./runner.sh -t <path to .ipynb file>` --------- Signed-off-by: Mingxin <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 0f77537 commit 3dfe68f

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

self_supervised_pretraining/swinunetr_pretrained/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ Benchmark on BTCV with using the pre-trained weights as compared to random initi
66

77
### Steps to run the tutorial
88
1. Download the dataset [BTCV](https://www.synapse.org/#!Synapse:syn3193805/wiki/217789) (More detail is provided in the Data section)
9-
2. Download the pretrained SwinUNETR weights on the 50,000 3D volumes from the following [link](https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/ssl_pretrained_weights.pth). More information about the dataset and training is provided below
10-
3. Modify the paths for pretrained_path, data_root, json_path & logdir in swinunetr_finetune.ipynb
11-
4. Run the 'swinunetr_finetune.ipynb'
9+
1. Modify the paths for pretrained_path, data_root, json_path & logdir in [swinunetr_finetune.ipynb](swinunetr_finetune.ipynb)
10+
1. Run the [swinunetr_finetune.ipynb](swinunetr_finetune.ipynb)
1211

1312
### 1. Data
1413
Pre-training Dataset: Datasets from multiple sources has been used. Below is a list of all the different datasets that were utilized for training the SwinUNETR network architecture:

self_supervised_pretraining/swinunetr_pretrained/swinunetr_finetune.ipynb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
"import matplotlib.pyplot as plt\n",
6565
"from collections import OrderedDict\n",
6666
"\n",
67+
"from monai.apps import download_url\n",
6768
"from monai.utils import set_determinism\n",
6869
"from monai.losses import DiceCELoss\n",
6970
"from monai.inferers import sliding_window_inference\n",
@@ -104,7 +105,7 @@
104105
"metadata": {},
105106
"source": [
106107
"##### Note:\n",
107-
"[Beyond the cranial vault](https://www.synapse.org/#!Synapse:syn3193805/wiki/217789) abdominal segmentation multi-class dataset needs to be downloaded for the execution of this notebook. Downloading data to the `data_root` path defined variable is optimal, if data is downloaded at another location please change the path `data_root` accordingly. Please make sure to download the pre-trained weights from [here](https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/ssl_pretrained_weights.pth) to use them in this notebook, the path to the downloaded pre-trained weights needs to be set.\n",
108+
"[Beyond the cranial vault](https://www.synapse.org/#!Synapse:syn3193805/wiki/217789) abdominal segmentation multi-class dataset needs to be downloaded for the execution of this notebook. Downloading data to the `data_root` path defined variable is optimal, if data is downloaded at another location please change the path `data_root` accordingly.\n",
108109
"\n",
109110
"Please see the Readme for more details about the dataset. Multiple data splits have already been provided in subsets of 3, 5, 7, 12 and 24 (full data) with consistent validation splits."
110111
]
@@ -152,7 +153,14 @@
152153
"outputs": [],
153154
"source": [
154155
"use_pretrained = True\n",
155-
"pretrained_path = os.path.normpath(\"to/be/defined\")"
156+
"\n",
157+
"if use_pretrained:\n",
158+
" resource = (\n",
159+
" \"https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/ssl_pretrained_weights.pth\"\n",
160+
" )\n",
161+
" dst = \"./ssl_pretrained_weights.pth\"\n",
162+
" download_url(resource, dst)\n",
163+
" pretrained_path = os.path.normpath(dst)"
156164
]
157165
},
158166
{
@@ -537,7 +545,7 @@
537545
"name": "python",
538546
"nbconvert_exporter": "python",
539547
"pygments_lexer": "ipython3",
540-
"version": "3.8.15"
548+
"version": "3.8.10"
541549
}
542550
},
543551
"nbformat": 4,

0 commit comments

Comments
 (0)