MCPcopy Create free account
hub / github.com/imrahulr/hat / init_attack

Method init_attack

core/utils/train.py:66–77  ·  view source on GitHub ↗

Initialize adversary.

(model, criterion, attack_type, attack_eps, attack_iter, attack_step)

Source from the content-addressed store, hash-verified

64
65 @staticmethod
66 def init_attack(model, criterion, attack_type, attack_eps, attack_iter, attack_step):
67 """
68 Initialize adversary.
69 """
70 attack = create_attack(model, criterion, attack_type, attack_eps, attack_iter, attack_step, rand_init_type='uniform')
71 if attack_type in ['linf-pgd', 'l2-pgd']:
72 eval_attack = create_attack(model, criterion, attack_type, attack_eps, 2*attack_iter, attack_step)
73 elif attack_type in ['fgsm', 'linf-df']:
74 eval_attack = create_attack(model, criterion, 'linf-pgd', 8/255, 20, 2/255)
75 elif attack_type in ['fgm', 'l2-df']:
76 eval_attack = create_attack(model, criterion, 'l2-pgd', 128/255, 20, 15/255)
77 return attack, eval_attack
78
79
80 def init_optimizer(self, num_epochs):

Callers 1

__init__Method · 0.95

Calls 1

create_attackFunction · 0.90

Tested by

no test coverage detected