Skip to content

Commit ba4c709

Browse files
committed
fixes
1 parent 71d7eee commit ba4c709

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

deepedit/ignite/infoANDinference.ipynb

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
"import numpy as np\n",
9999
"import torch\n",
100100
"from torch import jit\n",
101+
"import tempfile\n",
101102
"\n",
102103
"import monai\n",
103104
"from monai.config import print_config\n",
@@ -121,6 +122,7 @@
121122
" SqueezeDimd,\n",
122123
" ToNumpyd,\n",
123124
" ToTensord,\n",
125+
" FromMetaTensord,\n",
124126
")\n",
125127
"\n",
126128
"print_config()"
@@ -226,18 +228,16 @@
226228
],
227229
"source": [
228230
"# Download data and model\n",
231+
"data_dir = tempfile.TemporaryDirectory().name\n",
229232
"\n",
230233
"resource = \"https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/_image.nii.gz\"\n",
231-
"dst = \"_image.nii.gz\"\n",
232-
"\n",
233-
"if not os.path.exists(dst):\n",
234-
" monai.apps.download_url(resource, dst)\n",
234+
"image_path = os.path.join(data_dir, \"_image.nii.gz\")\n",
235+
"monai.apps.download_url(resource, image_path)\n",
235236
"\n",
236237
"resource = \"https://github.com/Project-MONAI/MONAI-extra-test-data/releases/\\\n",
237238
"download/0.8.1/pretrained_deepedit_dynunet-final.ts\"\n",
238-
"dst = \"pretrained_deepedit_dynunet-final.ts\"\n",
239-
"if not os.path.exists(dst):\n",
240-
" monai.apps.download_url(resource, dst)"
239+
"model_path = os.path.join(data_dir, \"pretrained_deepedit_dynunet-final.ts\")\n",
240+
"monai.apps.download_url(resource, model_path)"
241241
]
242242
},
243243
{
@@ -277,11 +277,12 @@
277277
"output_type": "stream",
278278
"text": [
279279
"EnsureChannelFirstd => image shape: (1, 392, 392, 210)\n",
280-
"Orientationd => image shape: (1, 392, 392, 210)\n",
281-
"ScaleIntensityRanged => image shape: (1, 392, 392, 210)\n",
282-
"AddGuidanceFromPointsDeepEditd => image shape: (1, 392, 392, 210)\n",
283-
"Resized => image shape: (1, 128, 128, 128)\n",
284-
"ResizeGuidanceMultipleLabelDeepEditd => image shape: (1, 128, 128, 128)\n",
280+
"FromMetaTensord => image shape: torch.Size([1, 392, 392, 210])\n",
281+
"Orientationd => image shape: torch.Size([1, 392, 392, 210])\n",
282+
"ScaleIntensityRanged => image shape: torch.Size([1, 392, 392, 210])\n",
283+
"AddGuidanceFromPointsDeepEditd => image shape: torch.Size([1, 392, 392, 210])\n",
284+
"Resized => image shape: torch.Size([1, 128, 128, 128])\n",
285+
"ResizeGuidanceMultipleLabelDeepEditd => image shape: torch.Size([1, 128, 128, 128])\n",
285286
"AddGuidanceSignalDeepEditd => image shape: (3, 128, 128, 128)\n",
286287
"ToTensord => image shape: torch.Size([3, 128, 128, 128])\n"
287288
]
@@ -297,7 +298,7 @@
297298
"spatial_size = [128, 128, 128]\n",
298299
"\n",
299300
"data = {\n",
300-
" 'image': '_image.nii.gz',\n",
301+
" 'image': image_path,\n",
301302
" 'guidance': {'spleen': [[66, 180, 105], [66, 180, 145]], 'background': []},\n",
302303
"}\n",
303304
"\n",
@@ -308,6 +309,8 @@
308309
" LoadImaged(keys=\"image\", reader=\"ITKReader\"),\n",
309310
" # Ensure channel first\n",
310311
" EnsureChannelFirstd(keys=\"image\"),\n",
312+
" # Convert away from MetaTensor\n",
313+
" FromMetaTensord(keys=\"image\"),\n",
311314
" # Change image orientation\n",
312315
" Orientationd(keys=\"image\", axcodes=\"RAS\"),\n",
313316
" # Scaling image intensity - works well for CT images\n",
@@ -475,7 +478,6 @@
475478
],
476479
"source": [
477480
"# Evaluation\n",
478-
"model_path = 'pretrained_deepedit_dynunet-final.ts'\n",
479481
"model = jit.load(model_path)\n",
480482
"model.cuda()\n",
481483
"model.eval()\n",
@@ -512,17 +514,6 @@
512514
" i, image.shape, label.shape, np.min(label), np.max(label), np.sum(label)))\n",
513515
" show_image(image, label)"
514516
]
515-
},
516-
{
517-
"cell_type": "code",
518-
"execution_count": 7,
519-
"metadata": {},
520-
"outputs": [],
521-
"source": [
522-
"# remove downloaded files\n",
523-
"os.remove('_image.nii.gz')\n",
524-
"os.remove('pretrained_deepedit_dynunet-final.ts')"
525-
]
526517
}
527518
],
528519
"metadata": {

0 commit comments

Comments
 (0)