Skip to content
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
91 changes: 59 additions & 32 deletions 3d_classification/densenet_training_array.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -131,40 +131,17 @@
}
],
"source": [
"# set this in your environment or previous cell to wherever IXI is downloaded and extracted\n",
"# Set data directory\n",
"directory = os.environ.get(\"MONAI_DATA_DIRECTORY\")\n",
"\n",
"if directory is None:\n",
" resource = \"http://biomedic.doc.ic.ac.uk/brain-development/downloads/IXI/IXI-T1.tar\"\n",
" md5 = \"34901a0593b41dd19c1a1f746eac2d58\"\n",
"\n",
" root_dir = tempfile.mkdtemp()\n",
"\n",
" dataset_dir = os.path.join(root_dir, \"ixi\")\n",
" tarfile_name = f\"{dataset_dir}.tar\"\n",
"\n",
" download_and_extract(resource, tarfile_name, dataset_dir, md5)\n",
"else:\n",
" root_dir = directory\n",
"\n",
"root_dir = tempfile.mkdtemp() if directory is None else directory\n",
"print(root_dir)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'torch.Tensor'> torch.Size([3, 1, 96, 96, 96]) tensor([[1., 0.],\n",
" [1., 0.],\n",
" [1., 0.]]) torch.Size([3, 2])\n"
]
}
],
"outputs": [],
"source": [
"# IXI dataset as a demo, downloadable from https://brain-development.org/ixi-dataset/\n",
"images = [\n",
Expand Down Expand Up @@ -195,8 +172,58 @@
"\n",
"# Represent labels in one-hot format for binary classifier training,\n",
"# BCEWithLogitsLoss requires target to have same shape as input\n",
"labels = torch.nn.functional.one_hot(torch.as_tensor(labels)).float()\n",
"labels = torch.nn.functional.one_hot(torch.as_tensor(labels)).float()"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"ixi.tar: 100%|██████████| 4.51G/4.51G [08:19<00:00, 9.70MB/s] \n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"2022-05-04 12:23:06,530 - INFO - Downloaded: /mnt/data/rbrown/Documents/Data/MONAI/ixi.tar\n",
"2022-05-04 12:23:13,734 - INFO - Verified 'ixi.tar', md5: 34901a0593b41dd19c1a1f746eac2d58.\n",
"2022-05-04 12:23:13,735 - INFO - Writing into directory: /mnt/data/rbrown/Documents/Data/MONAI/ixi.\n"
]
}
],
"source": [
"if not os.path.isfile(images[0]):\n",
" resource = \"http://biomedic.doc.ic.ac.uk/brain-development/downloads/IXI/IXI-T1.tar\"\n",
" md5 = \"34901a0593b41dd19c1a1f746eac2d58\"\n",
"\n",
" dataset_dir = os.path.join(root_dir, \"ixi\")\n",
" tarfile_name = f\"{dataset_dir}.tar\"\n",
"\n",
" download_and_extract(resource, tarfile_name, dataset_dir, md5)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'torch.Tensor'> torch.Size([3, 1, 96, 96, 96]) tensor([[1., 0.],\n",
" [1., 0.],\n",
" [1., 0.]]) torch.Size([3, 2])\n"
]
}
],
"source": [
"# Define transforms\n",
"train_transforms = Compose([ScaleIntensity(), AddChannel(), Resize((96, 96, 96)), RandRotate90(), EnsureType()])\n",
"\n",
Expand All @@ -220,7 +247,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -367,7 +394,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -395,7 +422,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -405,7 +432,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 10,
"metadata": {
"scrolled": true,
"tags": []
Expand Down Expand Up @@ -462,7 +489,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
Expand Down