|
131 | 131 | }
|
132 | 132 | ],
|
133 | 133 | "source": [
|
134 |
| - "# set this in your environment or previous cell to wherever IXI is downloaded and extracted\n", |
| 134 | + "# Set data directory\n", |
135 | 135 | "directory = os.environ.get(\"MONAI_DATA_DIRECTORY\")\n",
|
136 |
| - "\n", |
137 |
| - "if directory is None:\n", |
138 |
| - " resource = \"http://biomedic.doc.ic.ac.uk/brain-development/downloads/IXI/IXI-T1.tar\"\n", |
139 |
| - " md5 = \"34901a0593b41dd19c1a1f746eac2d58\"\n", |
140 |
| - "\n", |
141 |
| - " root_dir = tempfile.mkdtemp()\n", |
142 |
| - "\n", |
143 |
| - " dataset_dir = os.path.join(root_dir, \"ixi\")\n", |
144 |
| - " tarfile_name = f\"{dataset_dir}.tar\"\n", |
145 |
| - "\n", |
146 |
| - " download_and_extract(resource, tarfile_name, dataset_dir, md5)\n", |
147 |
| - "else:\n", |
148 |
| - " root_dir = directory\n", |
149 |
| - "\n", |
| 136 | + "root_dir = tempfile.mkdtemp() if directory is None else directory\n", |
150 | 137 | "print(root_dir)"
|
151 | 138 | ]
|
152 | 139 | },
|
153 | 140 | {
|
154 | 141 | "cell_type": "code",
|
155 | 142 | "execution_count": 4,
|
156 | 143 | "metadata": {},
|
157 |
| - "outputs": [ |
158 |
| - { |
159 |
| - "name": "stdout", |
160 |
| - "output_type": "stream", |
161 |
| - "text": [ |
162 |
| - "<class 'torch.Tensor'> torch.Size([3, 1, 96, 96, 96]) tensor([[1., 0.],\n", |
163 |
| - " [1., 0.],\n", |
164 |
| - " [1., 0.]]) torch.Size([3, 2])\n" |
165 |
| - ] |
166 |
| - } |
167 |
| - ], |
| 144 | + "outputs": [], |
168 | 145 | "source": [
|
169 | 146 | "# IXI dataset as a demo, downloadable from https://brain-development.org/ixi-dataset/\n",
|
170 | 147 | "images = [\n",
|
|
195 | 172 | "\n",
|
196 | 173 | "# Represent labels in one-hot format for binary classifier training,\n",
|
197 | 174 | "# BCEWithLogitsLoss requires target to have same shape as input\n",
|
198 |
| - "labels = torch.nn.functional.one_hot(torch.as_tensor(labels)).float()\n", |
| 175 | + "labels = torch.nn.functional.one_hot(torch.as_tensor(labels)).float()" |
| 176 | + ] |
| 177 | + }, |
| 178 | + { |
| 179 | + "cell_type": "code", |
| 180 | + "execution_count": 5, |
| 181 | + "metadata": {}, |
| 182 | + "outputs": [ |
| 183 | + { |
| 184 | + "name": "stderr", |
| 185 | + "output_type": "stream", |
| 186 | + "text": [ |
| 187 | + "ixi.tar: 100%|██████████| 4.51G/4.51G [08:19<00:00, 9.70MB/s] \n" |
| 188 | + ] |
| 189 | + }, |
| 190 | + { |
| 191 | + "name": "stdout", |
| 192 | + "output_type": "stream", |
| 193 | + "text": [ |
| 194 | + "2022-05-04 12:23:06,530 - INFO - Downloaded: /mnt/data/rbrown/Documents/Data/MONAI/ixi.tar\n", |
| 195 | + "2022-05-04 12:23:13,734 - INFO - Verified 'ixi.tar', md5: 34901a0593b41dd19c1a1f746eac2d58.\n", |
| 196 | + "2022-05-04 12:23:13,735 - INFO - Writing into directory: /mnt/data/rbrown/Documents/Data/MONAI/ixi.\n" |
| 197 | + ] |
| 198 | + } |
| 199 | + ], |
| 200 | + "source": [ |
| 201 | + "if not os.path.isfile(images[0]):\n", |
| 202 | + " resource = \"http://biomedic.doc.ic.ac.uk/brain-development/downloads/IXI/IXI-T1.tar\"\n", |
| 203 | + " md5 = \"34901a0593b41dd19c1a1f746eac2d58\"\n", |
199 | 204 | "\n",
|
| 205 | + " dataset_dir = os.path.join(root_dir, \"ixi\")\n", |
| 206 | + " tarfile_name = f\"{dataset_dir}.tar\"\n", |
| 207 | + "\n", |
| 208 | + " download_and_extract(resource, tarfile_name, dataset_dir, md5)" |
| 209 | + ] |
| 210 | + }, |
| 211 | + { |
| 212 | + "cell_type": "code", |
| 213 | + "execution_count": 6, |
| 214 | + "metadata": {}, |
| 215 | + "outputs": [ |
| 216 | + { |
| 217 | + "name": "stdout", |
| 218 | + "output_type": "stream", |
| 219 | + "text": [ |
| 220 | + "<class 'torch.Tensor'> torch.Size([3, 1, 96, 96, 96]) tensor([[1., 0.],\n", |
| 221 | + " [1., 0.],\n", |
| 222 | + " [1., 0.]]) torch.Size([3, 2])\n" |
| 223 | + ] |
| 224 | + } |
| 225 | + ], |
| 226 | + "source": [ |
200 | 227 | "# Define transforms\n",
|
201 | 228 | "train_transforms = Compose([ScaleIntensity(), AddChannel(), Resize((96, 96, 96)), RandRotate90(), EnsureType()])\n",
|
202 | 229 | "\n",
|
|
220 | 247 | },
|
221 | 248 | {
|
222 | 249 | "cell_type": "code",
|
223 |
| - "execution_count": 5, |
| 250 | + "execution_count": 7, |
224 | 251 | "metadata": {},
|
225 | 252 | "outputs": [
|
226 | 253 | {
|
|
367 | 394 | },
|
368 | 395 | {
|
369 | 396 | "cell_type": "code",
|
370 |
| - "execution_count": 6, |
| 397 | + "execution_count": 8, |
371 | 398 | "metadata": {},
|
372 | 399 | "outputs": [],
|
373 | 400 | "source": [
|
|
395 | 422 | },
|
396 | 423 | {
|
397 | 424 | "cell_type": "code",
|
398 |
| - "execution_count": 7, |
| 425 | + "execution_count": 9, |
399 | 426 | "metadata": {},
|
400 | 427 | "outputs": [],
|
401 | 428 | "source": [
|
|
405 | 432 | },
|
406 | 433 | {
|
407 | 434 | "cell_type": "code",
|
408 |
| - "execution_count": 8, |
| 435 | + "execution_count": 10, |
409 | 436 | "metadata": {
|
410 | 437 | "scrolled": true,
|
411 | 438 | "tags": []
|
|
462 | 489 | },
|
463 | 490 | {
|
464 | 491 | "cell_type": "code",
|
465 |
| - "execution_count": 9, |
| 492 | + "execution_count": 11, |
466 | 493 | "metadata": {},
|
467 | 494 | "outputs": [],
|
468 | 495 | "source": [
|
|
0 commit comments