-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
81 lines (67 loc) · 2.82 KB
/
main.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import logging
import argparse
from searchers import random as rs, mcts, regularized_evolution_searcher, smbo_random
from search_spaces import genetic_space, nasbench, nasnet_space, main_hierarchical
from evaluators import tpu_estimator_classification
from surrogates import hashing
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(name=__name__)
def run_search(searcher, evaluator, num_samples):
for evaluation_id in range(num_samples):
inputs, outputs, vs, sst = searcher.sample()
results = evaluator.eval(inputs, outputs)
results = {'validation_accuracy': .2}
searcher.update(results['validation_accuracy'], sst)
logger.info('Results evaluation %d:\n\tConfig:%s\n\tResults:%s',
evaluation_id, str(vs), str(results))
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--search-space',
choices=['genetic', 'nasnet', 'nasbench', 'flat'],
default='genetic')
parser.add_argument('--searcher',
choices=['random', 'mcts', 'smbo', 'evolution'],
default='random')
parser.add_argument('--data-dir', required=True)
parser.add_argument('--tpu-name', default='')
parser.add_argument('--use-tpu', action='store_true')
parser.add_argument('--evaluation-dir', default='./scratch')
parser.add_argument('--num-samples', type=int, default=128)
args = parser.parse_args()
if args.use_tpu and (args.tpu_name == '' or
not args.evaluation_dir.startswith('gs://') or
not args.data_dir.startswith('gs://')):
raise ValueError('If using TPU, TPU arguments need to be provided')
ssf_fns = {
'genetic': genetic_space.SSF_Genetic,
'nasnet': nasnet_space.SSF_NasnetA,
'nasbench': nasbench.SSF_Nasbench,
'flat': main_hierarchical.SSF_Flat,
}
ssf = ssf_fns[args.search_space]()
searcher_fns = {
'random':
lambda: rs.RandomSearcher(ssf.get_search_space),
'mcts':
lambda: mcts.MCTSSearcher(ssf.get_search_space, .33),
'smbo':
lambda: smbo_random.SMBOSearcher(
ssf.get_search_space, hashing.HashingSurrogate(2**16, 1), 512, .1),
'evolution':
lambda: regularized_evolution_searcher.EvolutionSearcher(
ssf.get_search_space,
regularized_evolution_searcher.mutatable,
100,
25,
regularized=True),
}
searcher = searcher_fns[args.searcher]()
evaluator = tpu_estimator_classification.AdvanceClassifierEvaluator(
args.data_dir,
args.tpu_name,
25,
base_dir=args.evaluation_dir,
use_tpu=args.use_tpu)
run_search(searcher, evaluator, args.num_samples)
if __name__ == '__main__':
main()