-
Notifications
You must be signed in to change notification settings - Fork 33
/
utils.py
24 lines (20 loc) · 1.17 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import torchvision.transforms as transforms
# from torchvision.transforms import Compose, Resize, ToTensor, Normalize, InterpolationMode
from AnomalyCLIP_lib.transform import image_transform
from AnomalyCLIP_lib.constants import OPENAI_DATASET_MEAN, OPENAI_DATASET_STD
def normalize(pred, max_value=None, min_value=None):
if max_value is None or min_value is None:
return (pred - pred.min()) / (pred.max() - pred.min())
else:
return (pred - min_value) / (max_value - min_value)
def get_transform(args):
preprocess = image_transform(args.image_size, is_train=False, mean = OPENAI_DATASET_MEAN, std = OPENAI_DATASET_STD)
target_transform = transforms.Compose([
transforms.Resize((args.image_size, args.image_size)),
transforms.CenterCrop(args.image_size),
transforms.ToTensor()
])
preprocess.transforms[0] = transforms.Resize(size=(args.image_size, args.image_size), interpolation=transforms.InterpolationMode.BICUBIC,
max_size=None, antialias=None)
preprocess.transforms[1] = transforms.CenterCrop(size=(args.image_size, args.image_size))
return preprocess, target_transform