Skip to content

Registration tutorial to use MONAI_DATA_DIRECTORY #668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 25 additions & 1 deletion 2d_registration/registration_mednist.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,36 @@
"import torch\n",
"from torch.nn import MSELoss\n",
"import matplotlib.pyplot as plt\n",
"import os\n",
"import tempfile\n",
"\n",
"\n",
"print_config()\n",
"set_determinism(42)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup data directory\n",
"\n",
"You can specify a directory with the `MONAI_DATA_DIRECTORY` environment variable. \n",
"This allows you to save results and reuse downloads. \n",
"If not specified a temporary directory will be used."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"directory = os.environ.get(\"MONAI_DATA_DIRECTORY\")\n",
"root_dir = tempfile.mkdtemp() if directory is None else directory\n",
"print(root_dir)"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -188,7 +212,7 @@
}
],
"source": [
"train_data = MedNISTDataset(root_dir=\"./\", section=\"training\", download=True, transform=None)\n",
"train_data = MedNISTDataset(root_dir=root_dir, section=\"training\", download=True, transform=None)\n",
"training_datadict = [\n",
" {\"fixed_hand\": item[\"image\"], \"moving_hand\": item[\"image\"]}\n",
" for item in train_data.data if item[\"label\"] == 4 # label 4 is for xray hands\n",
Expand Down