-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtrain_test_vgg16.py
39 lines (30 loc) · 1.09 KB
/
train_test_vgg16.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# coding: utf-8
import torch
from universal import universal_adversarial_perturbation
from prepare import fooling_rate, get_model
device = ('cuda' if torch.cuda.is_available() else 'cpu')
path_train_imagenet='/data/dongcheng/imgnet/train/'
path_test_imagenet='/data/dongcheng/imgnet/val/'
# noise=torch.load('noise_load.pth')
model = get_model('vgg16', device)
# compute noise
noise = universal_adversarial_perturbation(path_train_imagenet, model, device)
torch.save(noise, 'noise_load_vgg16.pth')
print("saving noise_load.pth")
print("vgg16:")
model = get_model('vgg16', device)
fr = fooling_rate(path_test_imagenet, noise, model, device)
print("vgg19:")
model = get_model('vgg19', device)
fr = fooling_rate(path_test_imagenet, noise, model, device)
'''
print("resnet18:")
model=get_model('resnet18',device)
fr,model = fooling_rate(path_test_imagene,tnoise,model, device)
'''
print("resnet152:")
model = get_model('resnet152', device)
fr = fooling_rate(path_test_imagenet, noise, model, device)
print("alexnet:")
model = get_model("alexnet", device)
fr = fooling_rate(path_test_imagenet, noise, model, device)