Skip to content

update 3d_registration tutorial #806

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 4 commits into from
Jul 19, 2022
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
34 changes: 11 additions & 23 deletions 3d_registration/paired_lung_ct.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,11 @@
"from monai.networks.blocks import Warp\n",
"from monai.networks.nets import LocalNet\n",
"from monai.transforms import (\n",
" AddChanneld,\n",
" Compose,\n",
" LoadImaged,\n",
" RandAffined,\n",
" Resized,\n",
" ScaleIntensityRanged,\n",
" EnsureTyped,\n",
")\n",
"from monai.utils import set_determinism, first\n",
"\n",
Expand Down Expand Up @@ -302,12 +300,10 @@
"source": [
"## Setup transforms for training and validation\n",
"Here we use several transforms to augment the dataset:\n",
"1. LoadImaged loads the lung CT images and labels from NIfTI format files.\n",
"2. AddChanneld as the original data doesn't have channel dim, add 1 dim to construct \"channel first\" shape.\n",
"3. ScaleIntensityRanged extracts intensity range [-285, 3770] and scales to [0, 1].\n",
"4. RandAffined efficiently performs rotate, scale, shear, translate, etc. together based on PyTorch affine transform.\n",
"5. Resized resize images to the same size.\n",
"6. EnsureTyped converts the numpy array to PyTorch Tensor for further steps."
"1. LoadImaged loads the lung CT images and labels from NIfTI format files. \"ensure_channel_first=True\" ensure that the first dim is channel.\n",
"2. ScaleIntensityRanged extracts intensity range [-285, 3770] and scales to [0, 1].\n",
"3. RandAffined efficiently performs rotate, scale, shear, translate, etc. together based on PyTorch affine transform.\n",
"4. Resized resize images to the same size."
]
},
{
Expand All @@ -324,10 +320,8 @@
"train_transforms = Compose(\n",
" [\n",
" LoadImaged(\n",
" keys=[\"fixed_image\", \"moving_image\", \"fixed_label\", \"moving_label\"]\n",
" ),\n",
" AddChanneld(\n",
" keys=[\"fixed_image\", \"moving_image\", \"fixed_label\", \"moving_label\"]\n",
" keys=[\"fixed_image\", \"moving_image\", \"fixed_label\", \"moving_label\"],\n",
" ensure_channel_first=True\n",
" ),\n",
" ScaleIntensityRanged(\n",
" keys=[\"fixed_image\", \"moving_image\"],\n",
Expand All @@ -345,18 +339,13 @@
" align_corners=(True, True, None, None),\n",
" spatial_size=(96, 96, 104)\n",
" ),\n",
" EnsureTyped(\n",
" keys=[\"fixed_image\", \"moving_image\", \"fixed_label\", \"moving_label\"]\n",
" ),\n",
" ]\n",
")\n",
"val_transforms = Compose(\n",
" [\n",
" LoadImaged(\n",
" keys=[\"fixed_image\", \"moving_image\", \"fixed_label\", \"moving_label\"]\n",
" ),\n",
" AddChanneld(\n",
" keys=[\"fixed_image\", \"moving_image\", \"fixed_label\", \"moving_label\"]\n",
" keys=[\"fixed_image\", \"moving_image\", \"fixed_label\", \"moving_label\"],\n",
" ensure_channel_first=True\n",
" ),\n",
" ScaleIntensityRanged(\n",
" keys=[\"fixed_image\", \"moving_image\"],\n",
Expand All @@ -369,9 +358,6 @@
" align_corners=(True, True, None, None),\n",
" spatial_size=(96, 96, 104)\n",
" ),\n",
" EnsureTyped(\n",
" keys=[\"fixed_image\", \"moving_image\", \"fixed_label\", \"moving_label\"]\n",
" ),\n",
" ]\n",
")"
]
Expand Down Expand Up @@ -693,6 +679,7 @@
"\n",
" val_ddf, val_pred_image, val_pred_label = forward(\n",
" val_data, model)\n",
" val_pred_label[val_pred_label > 1] = 1\n",
"\n",
" val_fixed_image = val_data[\"fixed_image\"].to(device)\n",
" val_fixed_label = val_data[\"fixed_label\"].to(device)\n",
Expand Down Expand Up @@ -723,6 +710,7 @@
" optimizer.zero_grad()\n",
"\n",
" ddf, pred_image, pred_label = forward(batch_data, model)\n",
" pred_label[pred_label > 1] = 1\n",
"\n",
" fixed_image = batch_data[\"fixed_image\"].to(device)\n",
" fixed_label = batch_data[\"fixed_label\"].to(device)\n",
Expand Down Expand Up @@ -1281,7 +1269,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.12"
"version": "3.8.13"
}
},
"nbformat": 4,
Expand Down