Skip to content

Commit

Permalink
Fix deprecated issue for IgniteInfo (#1849)
Browse files Browse the repository at this point in the history
Set `weights_only=True` because this warning.
```
You are using torch.load with weights_only=False (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See [pytorch/SECURITY.md at main · pytorch/pytorch · GitHub 2](https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models) for more details). In a future release, the default value for weights_only will be flipped to True. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via torch.serialization.add_safe_globals. We recommend you start setting weights_only=True for any use case where you don’t have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
```

### Checks
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Avoid including large-size files in the PR.
- [x] Clean up long text outputs from code cells in the notebook.
- [x] For security purposes, please check the contents and remove any
sensitive info such as user names and private key.
- [x] Ensure (1) hyperlinks and markdown anchors are working (2) use
relative paths for tutorial repo files (3) put figure and graphs in the
`./figure` folder
- [x] Notebook runs automatically `./runner.sh -t <path to .ipynb file>`

---------

Signed-off-by: YunLiu <[email protected]>
  • Loading branch information
KumoLiu authored Sep 30, 2024
1 parent 1ad4540 commit e4cf547
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 37 deletions.
4 changes: 2 additions & 2 deletions active_learning/tool_tracking_al/active_learning.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,10 +469,10 @@ def main():
variance = np.sum(np.nanvar(vol_input, axis=0), axis=0)

score_list.append(np.nanmean(variance))
name_list.append(unl_data["image_meta_dict"]["filename_or_obj"][0])
name_list.append(unl_data["image"].meta["filename_or_obj"][0])
print(
"Variance for image: {} is: {}".format(
unl_data["image_meta_dict"]["filename_or_obj"][0], np.nanmean(variance)
unl_data["image"].meta["filename_or_obj"][0], np.nanmean(variance)
)
)

Expand Down
65 changes: 34 additions & 31 deletions active_learning/tool_tracking_al/results_uncertainty_analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 1,
"id": "d5b36e92",
"metadata": {},
"outputs": [],
Expand All @@ -56,37 +56,40 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 2,
"id": "57ef4a1b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"MONAI version: 1.0.1\n",
"Numpy version: 1.23.4\n",
"Pytorch version: 1.13.0+cu117\n",
"MONAI version: 1.4.0rc10\n",
"Numpy version: 1.24.4\n",
"Pytorch version: 2.5.0a0+872d972e41.nv24.08.01\n",
"MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False\n",
"MONAI rev id: 8271a193229fe4437026185e218d5b06f7c8ce69\n",
"MONAI __file__: /home/vishwesh/anaconda3/envs/mtk_py38/lib/python3.8/site-packages/monai/__init__.py\n",
"MONAI rev id: cac21f6936a2e8d6e4e57e4e958f8e32aae1585e\n",
"MONAI __file__: /usr/local/lib/python3.10/dist-packages/monai/__init__.py\n",
"\n",
"Optional dependencies:\n",
"Pytorch Ignite version: 0.4.10\n",
"Nibabel version: 4.0.2\n",
"scikit-image version: 0.19.3\n",
"Pillow version: 9.3.0\n",
"Tensorboard version: 2.11.0\n",
"gdown version: 4.5.3\n",
"TorchVision version: 0.14.0+cu117\n",
"tqdm version: 4.64.1\n",
"lmdb version: 1.3.0\n",
"psutil version: 5.9.0\n",
"pandas version: 1.5.1\n",
"einops version: 0.6.0\n",
"transformers version: 4.21.3\n",
"mlflow version: 2.0.1\n",
"pynrrd version: 0.4.3\n",
"Pytorch Ignite version: 0.4.11\n",
"ITK version: 5.4.0\n",
"Nibabel version: 5.2.1\n",
"scikit-image version: 0.23.2\n",
"scipy version: 1.13.1\n",
"Pillow version: 10.4.0\n",
"Tensorboard version: 2.17.0\n",
"gdown version: 5.2.0\n",
"TorchVision version: 0.20.0a0\n",
"tqdm version: 4.66.4\n",
"lmdb version: 1.5.1\n",
"psutil version: 5.9.8\n",
"pandas version: 2.2.2\n",
"einops version: 0.7.0\n",
"transformers version: 4.40.2\n",
"mlflow version: 2.16.0\n",
"pynrrd version: 1.0.0\n",
"clearml version: 1.16.3\n",
"\n",
"For details about installing the optional dependencies, please visit:\n",
" https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies\n",
Expand Down Expand Up @@ -136,7 +139,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 3,
"id": "1d14c99c",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -188,7 +191,7 @@
").cuda()\n",
"\n",
"# Load Model Weights\n",
"model.load_state_dict(torch.load(model_ckpt))\n",
"model.load_state_dict(torch.load(model_ckpt, weights_only=True))\n",
"\n",
"# Please note that the model is being put to 'train' mode explicitly for Monte-Carlo simulations\n",
"model.train()\n",
Expand All @@ -197,16 +200,16 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 4,
"id": "22b9db61",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"/scratch_2/robo_tool_dataset_2023/robo_tool/dv13_00098.png\n",
"Variance for image: /scratch_2/robo_tool_dataset_2023/robo_tool/dv13_00098.png is: 0.0021140489261597395\n"
"/workspace/Data/robo_tool/dv13_00098.png\n",
"Variance for image: /workspace/Data/robo_tool/dv13_00098.png is: 0.005063239950686693\n"
]
},
{
Expand Down Expand Up @@ -286,7 +289,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"id": "cc913015",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -344,9 +347,9 @@
],
"metadata": {
"kernelspec": {
"display_name": "mtk_py38",
"display_name": "Python 3",
"language": "python",
"name": "mtk_py38"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -358,7 +361,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.15"
"version": "3.10.12"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
"import torch.distributed\n",
"from IPython.display import Image as IImage\n",
"from monai.apps.nuclick.transforms import AddLabelAsGuidanced, SetLabelClassd, SplitLabeld\n",
"from monai.config import IgniteInfo, print_config\n",
"from monai.config import print_config\n",
"from monai.data import CacheDataset, DataLoader\n",
"from monai.engines import SupervisedEvaluator, SupervisedTrainer\n",
"from monai.handlers import CheckpointSaver, ConfusionMatrix, StatsHandler, ValidationHandler, from_engine\n",
Expand All @@ -112,7 +112,7 @@
" SelectItemsd,\n",
" ToTensord,\n",
")\n",
"from monai.utils import min_version, optional_import\n",
"from monai.utils import min_version, optional_import, IgniteInfo\n",
"from PIL import Image, ImageDraw\n",
"from scipy.io import loadmat\n",
"from sklearn.metrics import classification_report\n",
Expand Down
4 changes: 2 additions & 2 deletions pathology/nuclick/nuclick_training_notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"import torch.distributed\n",
"from IPython.display import Image as IImage\n",
"from monai.apps.nuclick.transforms import AddPointGuidanceSignald, SplitLabeld\n",
"from monai.config import IgniteInfo, print_config\n",
"from monai.config import print_config\n",
"from monai.data import CacheDataset, DataLoader\n",
"from monai.engines import SupervisedEvaluator, SupervisedTrainer\n",
"from monai.handlers import CheckpointSaver, MeanDice, StatsHandler, ValidationHandler, from_engine\n",
Expand All @@ -114,7 +114,7 @@
" ScaleIntensityRangeD,\n",
" SelectItemsd,\n",
")\n",
"from monai.utils import min_version, optional_import\n",
"from monai.utils import min_version, optional_import, IgniteInfo\n",
"from PIL import Image\n",
"from scipy.io import loadmat\n",
"from tqdm import tqdm\n",
Expand Down

0 comments on commit e4cf547

Please sign in to comment.