Skip to content

Commit cbd0e85

Browse files
authored
Merge pull request #38 from Imageomics/32-warning
Enable torch.load weights_only=True
2 parents 3f65a47 + b9498fc commit cbd0e85

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/bioclip/predict.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
import json
23
import torch
34
from torchvision import transforms
@@ -19,6 +20,13 @@
1920
PRED_CLASSICATION_KEY = "classification"
2021
PRED_SCORE_KEY = "score"
2122

23+
24+
# Use secure model loading unless explicitly disabled.
25+
# See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more.
26+
if not "TORCH_FORCE_WEIGHTS_ONLY_LOAD" in os.environ:
27+
os.environ["TORCH_FORCE_WEIGHTS_ONLY_LOAD"] = "true"
28+
29+
2230
OPENA_AI_IMAGENET_TEMPLATE = [
2331
lambda c: f"a bad photo of a {c}.",
2432
lambda c: f"a photo of many {c}.",

0 commit comments

Comments
 (0)