-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval_pgd50-10_folder.py
58 lines (43 loc) · 1.52 KB
/
eval_pgd50-10_folder.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Evaluation with AutoAttack.
python eval-aa.py --fname_input xxx --eps_eval xxx --batch_size_for_eval xxx
"""
import json
import time
import tqdm
import argparse
import os
import numpy as np
import pandas as pd
import torch
import torch.nn as nn
from autoattack import AutoAttack
from core.data import get_data_info
from core.data import load_data
from core.models import create_model
from core.utils import Logger
from core.utils import seed
from core.utils.utils import str2bool, str2float
# Setup
def parser_eval():
"""
Parse input arguments (eval-adv.py, eval-corr.py, eval-aa.py).
"""
parser = argparse.ArgumentParser(description='Robustness evaluation.')
parser.add_argument('--folder', type=str, default='')
parser.add_argument('--early_stopping', type=str2bool, default=True)
parser.add_argument('--gpu', type = int, default=2)
return parser
parse = parser_eval()
args = parse.parse_args()
for experiment in tqdm.tqdm(os.listdir(args.folder)):
print(experiment)
if 'pert' in experiment:
eps = int(experiment.split('pert')[1].split('_')[0])
else:
eps=8
if os.path.exists(os.path.join(args.folder,experiment,'log-pgd50-10.log')):
print('Already exists')
elif os.path.exists(os.path.join(args.folder,experiment,'val_best.pt')):
bash_cmd = f'CUDA_VISIBLE_DEVICES={args.gpu} python3 eval_pgd50-10.py --eps_eval {eps} --fname_input ' + os.path.join(args.folder,experiment) + f' --early_stopping {args.early_stopping}'
os.system(bash_cmd)