Skip to content

Commit 9989820

Browse files
authored
Merge branch 'Project-MONAI:main' into main
2 parents d24a090 + 28b462c commit 9989820

File tree

172 files changed

+5176
-2006
lines changed

Some content is hidden

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

172 files changed

+5176
-2006
lines changed

.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_classification/mednist_tutorial.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@
575575
"metadata": {},
576576
"outputs": [],
577577
"source": [
578-
"model.load_state_dict(torch.load(os.path.join(root_dir, \"best_metric_model.pth\")))\n",
578+
"model.load_state_dict(torch.load(os.path.join(root_dir, \"best_metric_model.pth\"), weights_only=True))\n",
579579
"model.eval()\n",
580580
"y_true = []\n",
581581
"y_pred = []\n",

2d_regression/image_restoration.ipynb

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

2d_segmentation/torch/unet_evaluation_array.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def main(tempdir):
4747
val_loader = DataLoader(val_ds, batch_size=1, num_workers=1, pin_memory=torch.cuda.is_available())
4848
dice_metric = DiceMetric(include_background=True, reduction="mean", get_not_nans=False)
4949
post_trans = Compose([Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
50-
saver = SaveImage(output_dir="./output", output_ext=".png", output_postfix="seg")
50+
saver = SaveImage(output_dir="./output", output_ext=".png", output_postfix="seg", scale=255)
5151
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
5252
model = UNet(
5353
spatial_dims=2,
@@ -58,7 +58,7 @@ def main(tempdir):
5858
num_res_units=2,
5959
).to(device)
6060

61-
model.load_state_dict(torch.load("best_metric_model_segmentation2d_array.pth"))
61+
model.load_state_dict(torch.load("best_metric_model_segmentation2d_array.pth", weights_only=True))
6262
model.eval()
6363
with torch.no_grad():
6464
for val_data in val_loader:

2d_segmentation/torch/unet_evaluation_dict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def main(tempdir):
6161
val_loader = DataLoader(val_ds, batch_size=1, num_workers=4, collate_fn=list_data_collate)
6262
dice_metric = DiceMetric(include_background=True, reduction="mean", get_not_nans=False)
6363
post_trans = Compose([Activations(sigmoid=True), AsDiscrete(threshold=0.5)])
64-
saver = SaveImage(output_dir="./output", output_ext=".png", output_postfix="seg")
64+
saver = SaveImage(output_dir="./output", output_ext=".png", output_postfix="seg", scale=255)
6565
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
6666
model = UNet(
6767
spatial_dims=2,
@@ -72,7 +72,7 @@ def main(tempdir):
7272
num_res_units=2,
7373
).to(device)
7474

75-
model.load_state_dict(torch.load("best_metric_model_segmentation2d_dict.pth"))
75+
model.load_state_dict(torch.load("best_metric_model_segmentation2d_dict.pth", weights_only=True))
7676

7777
model.eval()
7878
with torch.no_grad():

3d_classification/torch/densenet_evaluation_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def main():
5757
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
5858
model = monai.networks.nets.DenseNet121(spatial_dims=3, in_channels=1, out_channels=2).to(device)
5959

60-
model.load_state_dict(torch.load("best_metric_model_classification3d_array.pth"))
60+
model.load_state_dict(torch.load("best_metric_model_classification3d_array.pth", weights_only=True))
6161
model.eval()
6262
with torch.no_grad():
6363
num_correct = 0.0

3d_classification/torch/densenet_evaluation_dict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def main():
6363
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
6464
model = monai.networks.nets.DenseNet121(spatial_dims=3, in_channels=1, out_channels=2).to(device)
6565

66-
model.load_state_dict(torch.load("best_metric_model_classification3d_dict.pth"))
66+
model.load_state_dict(torch.load("best_metric_model_classification3d_dict.pth", weights_only=True))
6767
model.eval()
6868
with torch.no_grad():
6969
num_correct = 0.0

3d_registration/learn2reg_nlst_paired_lung_ct.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,7 @@
872872
"source": [
873873
"# Automatic mixed precision (AMP) for faster training\n",
874874
"amp_enabled = True\n",
875-
"scaler = torch.cuda.amp.GradScaler()\n",
875+
"scaler = torch.GradScaler(\"cuda\")\n",
876876
"\n",
877877
"# Tensorboard\n",
878878
"if do_save:\n",
@@ -1127,7 +1127,7 @@
11271127
" )\n",
11281128
" # load model weights\n",
11291129
" filename_best_model = glob.glob(os.path.join(dir_load, \"segresnet_kpt_loss_best_tre*\"))[0]\n",
1130-
" model.load_state_dict(torch.load(filename_best_model))\n",
1130+
" model.load_state_dict(torch.load(filename_best_model, weights_only=True))\n",
11311131
" # to GPU\n",
11321132
" model.to(device)\n",
11331133
"\n",
@@ -1139,7 +1139,7 @@
11391139
"# Forward pass\n",
11401140
"model.eval()\n",
11411141
"with torch.no_grad():\n",
1142-
" with torch.cuda.amp.autocast(enabled=amp_enabled):\n",
1142+
" with torch.autocast(\"cuda\", enabled=amp_enabled):\n",
11431143
" ddf_image, ddf_keypoints, pred_image, pred_label = forward(\n",
11441144
" check_data[\"fixed_image\"].to(device),\n",
11451145
" check_data[\"moving_image\"].to(device),\n",

3d_registration/learn2reg_oasis_unpaired_brain_mr.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@
610610
"source": [
611611
"# Automatic mixed precision (AMP) for faster training\n",
612612
"amp_enabled = True\n",
613-
"scaler = torch.cuda.amp.GradScaler()\n",
613+
"scaler = torch.GradScaler(\"cuda\")\n",
614614
"\n",
615615
"# Tensorboard\n",
616616
"if do_save:\n",
@@ -646,7 +646,7 @@
646646
"\n",
647647
" # Forward pass and loss\n",
648648
" optimizer.zero_grad()\n",
649-
" with torch.cuda.amp.autocast(enabled=amp_enabled):\n",
649+
" with torch.autocast(\"cuda\", enabled=amp_enabled):\n",
650650
" ddf_image, pred_image, pred_label_one_hot = forward(\n",
651651
" fixed_image, moving_image, moving_label, model, warp_layer, num_classes=4\n",
652652
" )\n",
@@ -694,7 +694,7 @@
694694
" # moving_label_35 = batch_data[\"moving_label_35\"].to(device)\n",
695695
" n_steps += 1\n",
696696
" # Infer\n",
697-
" with torch.cuda.amp.autocast(enabled=amp_enabled):\n",
697+
" with torch.autocast(\"cuda\", enabled=amp_enabled):\n",
698698
" ddf_image, pred_image, pred_label_one_hot = forward(\n",
699699
" fixed_image, moving_image, moving_label_4, model, warp_layer, num_classes=4\n",
700700
" )\n",
@@ -840,7 +840,7 @@
840840
" model = VoxelMorph()\n",
841841
" # load model weights\n",
842842
" filename_best_model = glob.glob(os.path.join(dir_load, \"voxelmorph_loss_best_dice_*\"))[0]\n",
843-
" model.load_state_dict(torch.load(filename_best_model))\n",
843+
" model.load_state_dict(torch.load(filename_best_model, weights_only=True))\n",
844844
" # to GPU\n",
845845
" model.to(device)\n",
846846
"\n",
@@ -860,7 +860,7 @@
860860
"# Forward pass\n",
861861
"model.eval()\n",
862862
"with torch.no_grad():\n",
863-
" with torch.cuda.amp.autocast(enabled=amp_enabled):\n",
863+
" with torch.autocast(\"cuda\", enabled=amp_enabled):\n",
864864
" ddf_image, pred_image, pred_label_one_hot = forward(\n",
865865
" fixed_image, moving_image, moving_label_35, model, warp_layer, num_classes=35\n",
866866
" )"

3d_registration/paired_lung_ct.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -860,7 +860,7 @@
860860
"resource = \"https://github.com/Project-MONAI/MONAI-extra-test-data/releases/download/0.8.1/pair_lung_ct.pth\"\n",
861861
"dst = f\"{root_dir}/pretrained_weight.pth\"\n",
862862
"download_url(resource, dst)\n",
863-
"model.load_state_dict(torch.load(dst))"
863+
"model.load_state_dict(torch.load(dst, weights_only=True))"
864864
]
865865
},
866866
{

0 commit comments

Comments
 (0)