Add normalization layer with mean and std in training configuration
(model)
| 35 | |
| 36 | |
| 37 | def 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 | |
| 63 | def save_images(output_dir, adversaries, filenames): |
no test coverage detected