Skip to content

Commit 3842e59

Browse files
committed
fix torch.load deprecated error
Signed-off-by: YunLiu <[email protected]>
1 parent 0f21835 commit 3842e59

File tree

71 files changed

+106
-104
lines changed

Some content is hidden

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

71 files changed

+106
-104
lines changed

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_segmentation/torch/unet_evaluation_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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",

3d_registration/learn2reg_oasis_unpaired_brain_mr.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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",

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
{

3d_segmentation/brats_segmentation_3d.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@
733733
}
734734
],
735735
"source": [
736-
"model.load_state_dict(torch.load(os.path.join(root_dir, \"best_metric_model.pth\")))\n",
736+
"model.load_state_dict(torch.load(os.path.join(root_dir, \"best_metric_model.pth\"), weights_only=True))\n",
737737
"model.eval()\n",
738738
"with torch.no_grad():\n",
739739
" # select one image to evaluate and visualize the model output\n",
@@ -835,7 +835,7 @@
835835
}
836836
],
837837
"source": [
838-
"model.load_state_dict(torch.load(os.path.join(root_dir, \"best_metric_model.pth\")))\n",
838+
"model.load_state_dict(torch.load(os.path.join(root_dir, \"best_metric_model.pth\"), weights_only=True))\n",
839839
"model.eval()\n",
840840
"\n",
841841
"with torch.no_grad():\n",
@@ -977,7 +977,7 @@
977977
"source": [
978978
"onnx_model_path = os.path.join(root_dir, \"best_metric_model.onnx\")\n",
979979
"ort_session = onnxruntime.InferenceSession(onnx_model_path)\n",
980-
"model.load_state_dict(torch.load(os.path.join(root_dir, \"best_metric_model.pth\")))\n",
980+
"model.load_state_dict(torch.load(os.path.join(root_dir, \"best_metric_model.pth\"), weights_only=True))\n",
981981
"model.eval()\n",
982982
"\n",
983983
"with torch.no_grad():\n",

3d_segmentation/challenge_baseline/run_net.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ def infer(data_folder=".", model_folder="runs", prediction_folder="output"):
219219

220220
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
221221
net = get_net().to(device)
222-
net.load_state_dict(torch.load(ckpt, map_location=device))
222+
net.load_state_dict(torch.load(ckpt, map_location=device, weights_only=True))
223223
net.eval()
224224

225225
image_folder = os.path.abspath(data_folder)

0 commit comments

Comments
 (0)