Skip to content

Commit febeae7

Browse files
authored
Merge branch 'Project-MONAI:main' into maisi
2 parents b32390c + 8b90a16 commit febeae7

62 files changed

Lines changed: 917 additions & 145 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ repos:
2323
- id: detect-private-key
2424

2525
- repo: https://github.com/psf/black
26-
rev: "24.10.0"
26+
rev: "25.1.0"
2727
hooks:
2828
- id: black
2929
- id: black-jupyter

2d_regression/image_restoration.ipynb

Lines changed: 690 additions & 0 deletions
Large diffs are not rendered by default.

3d_regression/README.md

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
3D Regression
22
=============
33

4-
How to run the 3D regression tutorial.
5-
--------------------------------------
4+
This directory contains a tutorial demonstrating how to use MONAI for 3D regression tasks, specifically brain age prediction using the IXI dataset and a DenseNet3D architecture.
65

7-
Running this notebook is straightforward. It works well in Colab.
6+
## Tutorial Overview
7+
8+
The `densenet_training_array.ipynb` notebook provides an end-to-end example of:
9+
- Loading and preprocessing 3D brain MRI data
10+
- Setting up data transforms for regression tasks
11+
- Training a DenseNet3D model for age prediction
12+
- Evaluating model performance on test data
13+
14+
## How to Run
15+
16+
This notebook can be run locally with Jupyter or in Google Colab. The notebook includes all necessary setup instructions and dependency installations.
17+
18+
[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Project-MONAI/tutorials/blob/main/3d_regression/densenet_training_array.ipynb)

3d_segmentation/spleen_segmentation_3d.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@
284284
" b_max=1.0,\n",
285285
" clip=True,\n",
286286
" ),\n",
287-
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
287+
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
288288
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
289289
" Spacingd(keys=[\"image\", \"label\"], pixdim=(1.5, 1.5, 2.0), mode=(\"bilinear\", \"nearest\")),\n",
290290
" RandCropByPosNegLabeld(\n",
@@ -318,7 +318,7 @@
318318
" b_max=1.0,\n",
319319
" clip=True,\n",
320320
" ),\n",
321-
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
321+
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
322322
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
323323
" Spacingd(keys=[\"image\", \"label\"], pixdim=(1.5, 1.5, 2.0), mode=(\"bilinear\", \"nearest\")),\n",
324324
" ]\n",
@@ -690,7 +690,7 @@
690690
" b_max=1.0,\n",
691691
" clip=True,\n",
692692
" ),\n",
693-
" CropForegroundd(keys=[\"image\"], source_key=\"image\"),\n",
693+
" CropForegroundd(keys=[\"image\"], source_key=\"image\", allow_smaller=True),\n",
694694
" ]\n",
695695
")\n",
696696
"\n",
@@ -784,7 +784,7 @@
784784
" b_max=1.0,\n",
785785
" clip=True,\n",
786786
" ),\n",
787-
" CropForegroundd(keys=[\"image\"], source_key=\"image\"),\n",
787+
" CropForegroundd(keys=[\"image\"], source_key=\"image\", allow_smaller=True),\n",
788788
" ]\n",
789789
")\n",
790790
"\n",

3d_segmentation/spleen_segmentation_3d_lightning.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@
278278
" b_max=1.0,\n",
279279
" clip=True,\n",
280280
" ),\n",
281-
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
281+
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
282282
" # randomly crop out patch samples from\n",
283283
" # big image based on pos / neg ratio\n",
284284
" # the image centers of negative samples\n",
@@ -321,7 +321,7 @@
321321
" b_max=1.0,\n",
322322
" clip=True,\n",
323323
" ),\n",
324-
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
324+
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
325325
" ]\n",
326326
" )\n",
327327
"\n",

3d_segmentation/spleen_segmentation_3d_visualization_basic.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@
317317
" b_max=1.0,\n",
318318
" clip=True,\n",
319319
" ),\n",
320-
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
320+
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
321321
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
322322
" Spacingd(keys=[\"image\", \"label\"], pixdim=(1.5, 1.5, 2.0), mode=(\"bilinear\", \"nearest\")),\n",
323323
" RandCropByPosNegLabeld(\n",
@@ -351,7 +351,7 @@
351351
" b_max=1.0,\n",
352352
" clip=True,\n",
353353
" ),\n",
354-
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
354+
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
355355
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
356356
" Spacingd(keys=[\"image\", \"label\"], pixdim=(1.5, 1.5, 2.0), mode=(\"bilinear\", \"nearest\")),\n",
357357
" ]\n",
@@ -782,7 +782,7 @@
782782
" b_max=1.0,\n",
783783
" clip=True,\n",
784784
" ),\n",
785-
" CropForegroundd(keys=[\"image\"], source_key=\"image\"),\n",
785+
" CropForegroundd(keys=[\"image\"], source_key=\"image\", allow_smaller=True),\n",
786786
" ]\n",
787787
")\n",
788788
"\n",

3d_segmentation/swin_unetr_brats21_segmentation_3d.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@
326326
" keys=[\"image\", \"label\"],\n",
327327
" source_key=\"image\",\n",
328328
" k_divisible=[roi[0], roi[1], roi[2]],\n",
329+
" allow_smaller=True,\n",
329330
" ),\n",
330331
" transforms.RandSpatialCropd(\n",
331332
" keys=[\"image\", \"label\"],\n",
@@ -454,7 +455,7 @@
454455
"source": [
455456
"## Create Swin UNETR model\n",
456457
"\n",
457-
"In this scetion, we create Swin UNETR model for the 3-class brain tumor semantic segmentation. We use a feature size of 48. We also use gradient checkpointing (use_checkpoint) for more memory-efficient training. However, use_checkpoint for faster training if enough GPU memory is available. "
458+
"In this section, we create Swin UNETR model for the 3-class brain tumor semantic segmentation. We use a feature size of 48. We also use gradient checkpointing (use_checkpoint) for more memory-efficient training. However, use_checkpoint for faster training if enough GPU memory is available. "
458459
]
459460
},
460461
{
@@ -467,7 +468,6 @@
467468
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
468469
"\n",
469470
"model = SwinUNETR(\n",
470-
" img_size=roi,\n",
471471
" in_channels=4,\n",
472472
" out_channels=3,\n",
473473
" feature_size=48,\n",

3d_segmentation/swin_unetr_btcv_segmentation_3d.ipynb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696
"source": [
9797
"# Pre-trained Swin UNETR Encoder\n",
9898
"\n",
99-
"We use weights from self-supervised pre-training of Swin UNETR encoder (3D Swin Tranformer) on a cohort of 5050 CT scans from publicly available datasets. The encoder is pre-trained using reconstructin, rotation prediction and contrastive learning pre-text tasks as shown below. For more details, please refer to [1] (CVPR paper) and see this [repository](https://github.com/Project-MONAI/research-contributions/tree/main/SwinUNETR/Pretrain). \n",
99+
"We use weights from self-supervised pre-training of Swin UNETR encoder (3D Swin Transformer) on a cohort of 5050 CT scans from publicly available datasets. The encoder is pre-trained using reconstructin, rotation prediction and contrastive learning pre-text tasks as shown below. For more details, please refer to [1] (CVPR paper) and see this [repository](https://github.com/Project-MONAI/research-contributions/tree/main/SwinUNETR/Pretrain). \n",
100100
"\n",
101101
"Please download the pre-trained weights from this [link](https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/model_swinvit.pt) and place it in the root directory of this tutorial. \n",
102102
"\n",
@@ -243,7 +243,7 @@
243243
" b_max=1.0,\n",
244244
" clip=True,\n",
245245
" ),\n",
246-
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
246+
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
247247
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
248248
" Spacingd(\n",
249249
" keys=[\"image\", \"label\"],\n",
@@ -292,7 +292,7 @@
292292
" [\n",
293293
" LoadImaged(keys=[\"image\", \"label\"], ensure_channel_first=True),\n",
294294
" ScaleIntensityRanged(keys=[\"image\"], a_min=-175, a_max=250, b_min=0.0, b_max=1.0, clip=True),\n",
295-
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
295+
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
296296
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
297297
" Spacingd(\n",
298298
" keys=[\"image\", \"label\"],\n",
@@ -439,7 +439,6 @@
439439
"device = torch.device(\"cuda\" if torch.cuda.is_available() else \"cpu\")\n",
440440
"\n",
441441
"model = SwinUNETR(\n",
442-
" img_size=(96, 96, 96),\n",
443442
" in_channels=1,\n",
444443
" out_channels=14,\n",
445444
" feature_size=48,\n",
@@ -453,7 +452,7 @@
453452
"source": [
454453
"### Initialize Swin UNETR encoder from self-supervised pre-trained weights\n",
455454
"\n",
456-
"In this section, we intialize the Swin UNETR encoder from pre-trained weights. The weights can be downloaded using the wget command below, or by following [this link](https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/model_swinvit.pt) to GitHub. If training from scratch is desired, please skip this section."
455+
"In this section, we initialize the Swin UNETR encoder from pre-trained weights. The weights can be downloaded using the wget command below, or by following [this link](https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/model_swinvit.pt) to GitHub. If training from scratch is desired, please skip this section."
457456
]
458457
},
459458
{

3d_segmentation/unetr_btcv_segmentation_3d.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@
228228
" b_max=1.0,\n",
229229
" clip=True,\n",
230230
" ),\n",
231-
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
231+
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
232232
" RandCropByPosNegLabeld(\n",
233233
" keys=[\"image\", \"label\"],\n",
234234
" label_key=\"label\",\n",
@@ -277,7 +277,7 @@
277277
" mode=(\"bilinear\", \"nearest\"),\n",
278278
" ),\n",
279279
" ScaleIntensityRanged(keys=[\"image\"], a_min=-175, a_max=250, b_min=0.0, b_max=1.0, clip=True),\n",
280-
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
280+
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
281281
" ]\n",
282282
")"
283283
]

3d_segmentation/unetr_btcv_segmentation_3d_lightning.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@
466466
" b_max=1.0,\n",
467467
" clip=True,\n",
468468
" ),\n",
469-
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
469+
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
470470
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
471471
" Spacingd(\n",
472472
" keys=[\"image\", \"label\"],\n",
@@ -522,7 +522,7 @@
522522
" b_max=1.0,\n",
523523
" clip=True,\n",
524524
" ),\n",
525-
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\"),\n",
525+
" CropForegroundd(keys=[\"image\", \"label\"], source_key=\"image\", allow_smaller=True),\n",
526526
" Orientationd(keys=[\"image\", \"label\"], axcodes=\"RAS\"),\n",
527527
" Spacingd(\n",
528528
" keys=[\"image\", \"label\"],\n",

0 commit comments

Comments
 (0)