Skip to content

Commit 404a92b

Browse files
authored
Registration tutorial to use MONAI_DATA_DIRECTORY (Project-MONAI#668)
* Registration tutorial to use MONAI_DATA_DIRECTORY
1 parent 8f5c308 commit 404a92b

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

2d_registration/registration_mednist.ipynb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,36 @@
119119
"import torch\n",
120120
"from torch.nn import MSELoss\n",
121121
"import matplotlib.pyplot as plt\n",
122+
"import os\n",
123+
"import tempfile\n",
122124
"\n",
123125
"\n",
124126
"print_config()\n",
125127
"set_determinism(42)"
126128
]
127129
},
130+
{
131+
"cell_type": "markdown",
132+
"metadata": {},
133+
"source": [
134+
"## Setup data directory\n",
135+
"\n",
136+
"You can specify a directory with the `MONAI_DATA_DIRECTORY` environment variable. \n",
137+
"This allows you to save results and reuse downloads. \n",
138+
"If not specified a temporary directory will be used."
139+
]
140+
},
141+
{
142+
"cell_type": "code",
143+
"execution_count": null,
144+
"metadata": {},
145+
"outputs": [],
146+
"source": [
147+
"directory = os.environ.get(\"MONAI_DATA_DIRECTORY\")\n",
148+
"root_dir = tempfile.mkdtemp() if directory is None else directory\n",
149+
"print(root_dir)"
150+
]
151+
},
128152
{
129153
"cell_type": "markdown",
130154
"metadata": {
@@ -188,7 +212,7 @@
188212
}
189213
],
190214
"source": [
191-
"train_data = MedNISTDataset(root_dir=\"./\", section=\"training\", download=True, transform=None)\n",
215+
"train_data = MedNISTDataset(root_dir=root_dir, section=\"training\", download=True, transform=None)\n",
192216
"training_datadict = [\n",
193217
" {\"fixed_hand\": item[\"image\"], \"moving_hand\": item[\"image\"]}\n",
194218
" for item in train_data.data if item[\"label\"] == 4 # label 4 is for xray hands\n",

0 commit comments

Comments
 (0)