MCPcopy Create free account
hub / github.com/Trustworthy-AI-Group/TransferAttack / wrap_model

Function wrap_model

transferattack/utils.py:37–60  ·  view source on GitHub ↗

Add normalization layer with mean and std in training configuration

(model)

Source from the content-addressed store, hash-verified

35
36
37def wrap_model(model):
38 """
39 Add normalization layer with mean and std in training configuration
40 """
41 model_name = model.__class__.__name__
42 Resize = 224
43
44 if hasattr(model, 'default_cfg'):
45 """timm.models"""
46 mean = model.default_cfg['mean']
47 std = model.default_cfg['std']
48 else:
49 """torchvision.models"""
50 if 'Inc' in model_name:
51 mean = [0.5, 0.5, 0.5]
52 std = [0.5, 0.5, 0.5]
53 Resize = 299
54 else:
55 mean = [0.485, 0.456, 0.406]
56 std = [0.229, 0.224, 0.225]
57 Resize = 224
58
59 PreprocessModel = PreprocessingModel(Resize, mean, std)
60 return torch.nn.Sequential(PreprocessModel, model)
61
62
63def save_images(output_dir, adversaries, filenames):

Callers 15

load_single_modelMethod · 0.70
mainFunction · 0.50
load_modelMethod · 0.50
load_modelMethod · 0.50
load_modelMethod · 0.50
load_modelMethod · 0.50
load_modelMethod · 0.50
load_modelMethod · 0.50
load_modelMethod · 0.50
load_modelMethod · 0.50
load_modelMethod · 0.50
load_modelMethod · 0.50

Calls 1

PreprocessingModelClass · 0.85

Tested by

no test coverage detected