Skip to content

Commit d4faeb4

Browse files
authored
Merge branch 'main' into 2015-improve-explanation-of-datalist-format
2 parents e19883d + 9948f26 commit d4faeb4

File tree

8 files changed

+91
-48
lines changed

8 files changed

+91
-48
lines changed

.github/workflows/test-modified.yml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,39 @@ on:
99

1010
concurrency:
1111
# automatically cancel the previously triggered workflows when there's a newer version
12-
group: build-gpu-${{ github.event.pull_request.number || github.ref }}
12+
group: build-${{ github.event.pull_request.number || github.ref }}
1313
cancel-in-progress: true
1414

1515
jobs:
1616
build:
17-
if: github.repository == 'Project-MONAI/tutorials'
18-
container:
19-
image: nvcr.io/nvidia/pytorch:24.02-py3
20-
options: --gpus all --ipc host
21-
runs-on: [self-hosted, linux, x64]
17+
runs-on: ubuntu-latest
2218
steps:
19+
- uses: actions/checkout@v3
20+
- name: Set up Python 3.10
21+
uses: actions/setup-python@v3
22+
with:
23+
python-version: '3.10'
2324
- name: Install MONAI
2425
id: monai-install
2526
run: |
2627
which python
27-
nvidia-smi
28-
rm -rf ../../MONAI/MONAI
29-
python -m pip install --upgrade pip wheel
30-
pip uninstall -y monai
31-
pip uninstall -y monai
32-
pip uninstall -y monai-weekly
33-
pip uninstall -y monai-weekly # make sure there's no existing installation
34-
BUILD_MONAI=0 python -m pip install git+https://github.com/Project-MONAI/MONAI#egg=MONAI
28+
python -m pip install -U pip wheel
29+
python -m pip install torch torchvision torchaudio
30+
3531
python -m pip install -r https://raw.githubusercontent.com/Project-MONAI/MONAI/dev/requirements-dev.txt
36-
python -m pip install -U torch torchvision torchaudio
37-
- uses: actions/checkout@v3
32+
python -m pip install -r requirements.txt
33+
34+
BUILD_MONAI=0 python -m pip install git+https://github.com/Project-MONAI/MONAI#egg=MONAI
35+
python -m pip list
3836
- name: Notebook quick check
3937
shell: bash
4038
run: |
41-
git config --global --add safe.directory /__w/tutorials/tutorials
42-
git fetch origin main
43-
python -m pip install -r requirements.txt; python -m pip list
4439
python -c "import monai; monai.config.print_debug_info()"
45-
export CUDA_VISIBLE_DEVICES=0
46-
git diff --name-only origin/main | while read line; do if [[ $line == *.ipynb ]]; then ./runner.sh -p " -and -wholename './${line}'"; fi; done;
47-
# [[ $line == *.ipynb ]] && ./runner.sh --file "$line"
40+
git fetch origin main
41+
git diff --name-only origin/main | while read line
42+
do
43+
if [[ $line == *.ipynb ]]
44+
then
45+
./runner.sh -p " -and -wholename './${line}'"
46+
fi
47+
done

2d_classification/monai_101.ipynb

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -141,15 +141,7 @@
141141
"cell_type": "code",
142142
"execution_count": null,
143143
"metadata": {},
144-
"outputs": [
145-
{
146-
"name": "stdout",
147-
"output_type": "stream",
148-
"text": [
149-
"/workspace/data\n"
150-
]
151-
}
152-
],
144+
"outputs": [],
153145
"source": [
154146
"directory = os.environ.get(\"MONAI_DATA_DIRECTORY\")\n",
155147
"if directory is not None:\n",
@@ -250,11 +242,12 @@
250242
"outputs": [],
251243
"source": [
252244
"max_epochs = 5\n",
253-
"model = densenet121(spatial_dims=2, in_channels=1, out_channels=6).to(\"cuda:0\")\n",
245+
"device = torch.device(\"cuda:0\" if torch.cuda.device_count() > 0 else \"cpu\")\n",
246+
"model = densenet121(spatial_dims=2, in_channels=1, out_channels=6).to(device)\n",
254247
"\n",
255248
"logging.basicConfig(stream=sys.stdout, level=logging.INFO)\n",
256249
"trainer = SupervisedTrainer(\n",
257-
" device=torch.device(\"cuda:0\"),\n",
250+
" device=device,\n",
258251
" max_epochs=max_epochs,\n",
259252
" train_data_loader=DataLoader(dataset, batch_size=512, shuffle=True, num_workers=4),\n",
260253
" network=model,\n",
@@ -320,7 +313,7 @@
320313
"max_items_to_print = 10\n",
321314
"with eval_mode(model):\n",
322315
" for item in DataLoader(testdata, batch_size=1, num_workers=0):\n",
323-
" prob = np.array(model(item[\"image\"].to(\"cuda:0\")).detach().to(\"cpu\"))[0]\n",
316+
" prob = np.array(model(item[\"image\"].to(device)).detach().to(\"cpu\"))[0]\n",
324317
" pred = class_names[prob.argmax()]\n",
325318
" gt = item[\"class_name\"][0]\n",
326319
" print(f\"Class prediction is {pred}. Ground-truth: {gt}\")\n",

3d_segmentation/spleen_segmentation_3d_visualization_basic.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@
484484
"# standard PyTorch program style: create UNet, DiceLoss and Adam optimizer\n",
485485
"device = torch.device(\"cuda:0\")\n",
486486
"\n",
487-
"UNet_meatdata = {\n",
487+
"UNet_metadata = {\n",
488488
" \"spatial_dims\": 3,\n",
489489
" \"in_channels\": 1,\n",
490490
" \"out_channels\": 2,\n",
@@ -494,7 +494,7 @@
494494
" \"norm\": Norm.BATCH,\n",
495495
"}\n",
496496
"\n",
497-
"model = UNet(**UNet_meatdata).to(device)\n",
497+
"model = UNet(**UNet_metadata).to(device)\n",
498498
"loss_function = DiceLoss(to_onehot_y=True, softmax=True)\n",
499499
"loss_type = \"DiceLoss\"\n",
500500
"optimizer = torch.optim.Adam(model.parameters(), 1e-4)\n",
@@ -539,7 +539,7 @@
539539
"# initialize a new Aim Run\n",
540540
"aim_run = aim.Run()\n",
541541
"# log model metadata\n",
542-
"aim_run[\"UNet_meatdata\"] = UNet_meatdata\n",
542+
"aim_run[\"UNet_metadata\"] = UNet_metadata\n",
543543
"# log optimizer metadata\n",
544544
"aim_run[\"Optimizer_metadata\"] = Optimizer_metadata\n",
545545
"\n",

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,50 @@ Running:
4141

4242
in a cell will verify this has worked and show you what kind of hardware you have access to.
4343

44+
#### Google Colab Setup (CUDA 12.x, PyTorch 2.6, MONAI 1.5)
45+
46+
In Google Colab, the default environment may cause version conflicts with MONAI.
47+
To ensure compatibility, install PyTorch and MONAI explicitly as follows:
48+
49+
# Install PyTorch 2.6.0 with CUDA 12.4
50+
pip install --index-url https://download.pytorch.org/whl/cu124 \
51+
torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0
52+
53+
# Install MONAI and common dependencies
54+
pip install "monai[all]" nibabel pydicom ipywidgets==8.1.2
55+
56+
57+
### Known issues and fixes
58+
59+
- Torchaudio mismatch
60+
Colab may come with torchaudio 2.8.0, which is incompatible with torch 2.6.0.
61+
Installing the versions above resolves this issue.
62+
63+
- filelock conflicts with nni
64+
Some preinstalled packages (such as pytensor with newer filelock) may conflict.
65+
Use the following commands to fix:
66+
67+
pip uninstall -y pytensor
68+
pip install -U filelock
69+
70+
- Too many workers warning
71+
Colab has limited CPU resources, and high num_workers settings may freeze execution.
72+
It is recommended to use --num_workers=2 when running tutorials and adjust the `num_workers` parameters where it is used in notebooks (eg. for data loaders).
73+
74+
75+
### Quick smoke test
76+
77+
After installation, verify the environment by running:
78+
79+
git clone https://github.com/Project-MONAI/tutorials.git
80+
cd tutorials/3d_segmentation/torch
81+
python -u unet_training_array.py --max_epochs 2 --batch_size 1 --num_workers 2
82+
83+
If the logs show decreasing training loss and a Dice score, the setup is correct.
84+
85+
**Note:** In most cases, users can run MONAI tutorials directly in Colab notebooks without additional installation.
86+
The steps above are mainly for resolving dependency conflicts when installing extra packages.
87+
4488
#### Data
4589

4690
Some notebooks will require additional data.

generation/maisi/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ We are excited to announce the new MAISI Version `maisi3d-rflow`. Compared with
2020
- For the released model weights, `maisi3d-rflow` can generate images with better quality for head region and small output volumes than `maisi3d-ddpm`; they have comparable quality for other cases.
2121
- `maisi3d-rflow` added a diffusion model input `modality`, which gives it flexibility to extend to other modalities. Currently it is set as always equal to 1 since this version only supports CT generation. We predefined some modalities in [./configs/modality_mapping.json](./configs/modality_mapping.json).
2222

23+
More details can be found in our 2025 report:
24+
25+
[Zhao, C., Guo, P., Yang, D., Tang, Y., ... & Xu, D. (2025). MAISI-v2: Accelerated 3D High-Resolution Medical Image Synthesis with Rectified Flow and Region-specific Contrastive Loss](https://arxiv.org/pdf/2508.05772)
26+
2327
**GUI demo:** Welcome to try our GUI demo at [https://build.nvidia.com/nvidia/maisi](https://build.nvidia.com/nvidia/maisi).
2428
The GUI is only a demo for toy examples. This Github repo is the full version.
2529

generation/maisi/maisi_train_vae_tutorial.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@
692692
},
693693
{
694694
"cell_type": "code",
695-
"execution_count": 14,
695+
"execution_count": null,
696696
"id": "4c251a32-390f-46dd-a613-75b12a7884c1",
697697
"metadata": {
698698
"scrolled": true
@@ -850,7 +850,7 @@
850850
" with torch.no_grad():\n",
851851
" with autocast(\"cuda\", enabled=args.amp):\n",
852852
" images = batch[\"image\"]\n",
853-
" reconstruction, _, _ = dynamic_infer(val_inferer, autoencoder, images)\n",
853+
" reconstruction, z_mu, z_sigma = dynamic_infer(val_inferer, autoencoder, images)\n",
854854
" reconstruction = reconstruction.to(device)\n",
855855
" val_epoch_losses[\"recons_loss\"] += intensity_loss(reconstruction, images.to(device)).item()\n",
856856
" val_epoch_losses[\"kl_loss\"] += KL_loss(z_mu, z_sigma).item()\n",

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ autopep8
44
jupytext<=1.16.3
55
autoflake
66
ipywidgets
7+
ipykernel
78
tensorboard>=2.4.0

runner.sh

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ skip_run_papermill=("${skip_run_papermill[@]}" .*unet_segmentation_3d_ignite_cle
131131
skip_run_papermill=("${skip_run_papermill[@]}" .*vista_2d_tutorial_monai.ipynb*)
132132
skip_run_papermill=("${skip_run_papermill[@]}" .*learn2reg_oasis_unpaired_brain_mr.ipynb*)
133133
skip_run_papermill=("${skip_run_papermill[@]}" .*finetune_vista3d_for_hugging_face_pipeline.ipynb*)
134+
skip_run_papermill=("${skip_run_papermill[@]}" .*TCIA_PROSTATEx_Prostate_MRI_Anatomy_Model.ipynb*) # https://github.com/Project-MONAI/tutorials/issues/2029
134135

135136
# output formatting
136137
separator=""
@@ -466,6 +467,15 @@ trap finish EXIT
466467
# After setup, don't want to exit immediately after error
467468
set +e
468469

470+
# FIXME: https://github.com/Project-MONAI/MONAI/issues/4354
471+
protobuf_major_version=$(${PY_EXE} -m pip list | grep '^protobuf ' | tr -s ' ' | cut -d' ' -f2 | cut -d'.' -f1)
472+
if [ "$protobuf_major_version" -ge "4" ]
473+
then
474+
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
475+
else
476+
unset PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION
477+
fi
478+
469479
########################################################################
470480
# #
471481
# loop over files #
@@ -559,15 +569,6 @@ for file in "${files[@]}"; do
559569

560570
python -c 'import monai; monai.config.print_config()'
561571

562-
# FIXME: https://github.com/Project-MONAI/MONAI/issues/4354
563-
protobuf_major_version=$(${PY_EXE} -m pip list | grep '^protobuf ' | tr -s ' ' | cut -d' ' -f2 | cut -d'.' -f1)
564-
if [ "$protobuf_major_version" -ge "4" ]
565-
then
566-
export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python
567-
else
568-
unset PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION
569-
fi
570-
571572
cmd=$(echo "papermill ${papermill_opt} --progress-bar --log-output -k ${kernelspec}")
572573
echo "$cmd"
573574
time out=$(echo "$notebook" | eval "$cmd")

0 commit comments

Comments
 (0)