Skip to content

Commit 2f6dc85

Browse files
committed
fix comments
Signed-off-by: binliu <[email protected]>
1 parent 92f13c8 commit 2f6dc85

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

hugging_face/hugging_face_pipeline_for_monai.ipynb

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@
136136
"import numpy as np\n",
137137
"import os\n",
138138
"import glob\n",
139+
"import shutil\n",
139140
"\n",
140141
"from transformers import PretrainedConfig, PreTrainedModel, Pipeline\n",
141142
"\n",
@@ -474,33 +475,25 @@
474475
},
475476
{
476477
"cell_type": "code",
477-
"execution_count": null,
478+
"execution_count": 9,
478479
"metadata": {},
479480
"outputs": [
480481
{
481482
"name": "stdout",
482483
"output_type": "stream",
483484
"text": [
484-
"2025-03-11 12:56:28,012 - INFO - --- input summary of monai.bundle.scripts.download ---\n",
485-
"2025-03-11 12:56:28,012 - INFO - > name: 'spleen_ct_segmentation'\n",
486-
"2025-03-11 12:56:28,012 - INFO - > bundle_dir: '.'\n",
487-
"2025-03-11 12:56:28,013 - INFO - > source: 'monaihosting'\n",
488-
"2025-03-11 12:56:28,013 - INFO - > remove_prefix: 'monai_'\n",
489-
"2025-03-11 12:56:28,013 - INFO - > progress: False\n",
490-
"2025-03-11 12:56:28,013 - INFO - ---\n",
485+
"2025-03-14 12:21:39,435 - INFO - --- input summary of monai.bundle.scripts.download ---\n",
486+
"2025-03-14 12:21:39,435 - INFO - > name: 'spleen_ct_segmentation'\n",
487+
"2025-03-14 12:21:39,435 - INFO - > bundle_dir: '.'\n",
488+
"2025-03-14 12:21:39,436 - INFO - > source: 'monaihosting'\n",
489+
"2025-03-14 12:21:39,436 - INFO - > remove_prefix: 'monai_'\n",
490+
"2025-03-14 12:21:39,437 - INFO - > progress: False\n",
491+
"2025-03-14 12:21:39,437 - INFO - ---\n",
491492
"\n",
492493
"\n",
493-
"2025-03-11 12:56:28,654 - INFO - Expected md5 is None, skip md5 check for file spleen_ct_segmentation_v0.5.9.zip.\n",
494-
"2025-03-11 12:56:28,656 - INFO - File exists: spleen_ct_segmentation_v0.5.9.zip, skipped downloading.\n",
495-
"2025-03-11 12:56:28,657 - INFO - Writing into directory: ..\n"
496-
]
497-
},
498-
{
499-
"name": "stderr",
500-
"output_type": "stream",
501-
"text": [
502-
"WARNING:py.warnings: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 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.\n",
503-
"\n"
494+
"2025-03-14 12:21:40,325 - INFO - Expected md5 is None, skip md5 check for file spleen_ct_segmentation_v0.5.9.zip.\n",
495+
"2025-03-14 12:21:40,327 - INFO - File exists: spleen_ct_segmentation_v0.5.9.zip, skipped downloading.\n",
496+
"2025-03-14 12:21:40,329 - INFO - Writing into directory: ..\n"
504497
]
505498
},
506499
{
@@ -532,7 +525,7 @@
532525
"\n",
533526
"config = MONAIUNetConfig()\n",
534527
"monai_unet = MONAIUNet(config)\n",
535-
"monai_unet.unet.load_state_dict(torch.load(weight_dir))\n",
528+
"monai_unet.unet.load_state_dict(torch.load(weight_dir, weights_only=True))\n",
536529
"pipeline = SpleenCTSegmentationPipeline(model=monai_unet, device=torch.device(\"cuda:0\"), save_output=False)\n",
537530
"\n",
538531
"numpy_transform = ToNumpy()\n",
@@ -558,6 +551,25 @@
558551
" plt.imshow(pred_output[:, :, 20])\n",
559552
" plt.show()"
560553
]
554+
},
555+
{
556+
"cell_type": "markdown",
557+
"metadata": {},
558+
"source": [
559+
"## Cleanup data directory\n",
560+
"\n",
561+
"Remove directory if a temporary was used."
562+
]
563+
},
564+
{
565+
"cell_type": "code",
566+
"execution_count": 10,
567+
"metadata": {},
568+
"outputs": [],
569+
"source": [
570+
"if directory is None:\n",
571+
" shutil.rmtree(root_dir)"
572+
]
561573
}
562574
],
563575
"metadata": {

0 commit comments

Comments
 (0)