-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
executable file
·112 lines (89 loc) · 3.98 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import argparse
from datetime import datetime
import logging
import general.utils as utils
import auto_profiler
import importlib
import constants
import general.utils
@auto_profiler.Profiler(depth=8, on_disable=general.utils.logProfile)
def run(args):
importlib.reload(constants)
from constants import methods
logger = logging.getLogger(__file__)
logger.debug(f'args={args}')
if (args.dataset < 0):
logger.error('Invalid dataset argument')
return
if (args.mlstrategy < 0):
logger.error('Invalid mlstrategy argument')
return
if (args.evaluation < 0):
logger.error('Invalid evaluation argument')
return
# logger.info(f'dataset={datasetdscr}')
strategy = methods.mlstrategy[args.mlstrategy]['method']()
evaluation = methods.evaluation[args.evaluation]['method']()
if (args.feature_extraction >= 0):
methods.feature_extraction = [methods.feature_extraction[args.feature_extraction]]
if (args.segmentation >= 0):
methods.segmentation = [methods.segmentation[args.segmentation]]
if args.seg_params:
for allkp in args.seg_params:
for kp in allkp.split(','):
k, p = kp.split('=')
for entry in methods.segmentation[0]['params']:
if k in entry:
entry[k] = float(p)
if 'var' in entry and entry['var'] == k:
entry['init'] = float(p)
print(args.seg_params)
# print('segme', methods.segmentation)
# return
if (args.classifier >= 0):
methods.classifier = [methods.classifier[args.classifier]]
datasetdscr = methods.dataset[args.dataset]['method']().load()
run_date = datetime.now().strftime('%y%m%d_%H-%M-%S')
filename = f'{run_date}-{datasetdscr.shortname()}-s={args.segmentation}'
methods.run_names = {'out': filename}
evalres = evaluation.evaluate(datasetdscr, strategy)
run_info = {
'dataset': datasetdscr.shortname(),
'run_date': run_date,
'dataset_path': datasetdscr.data_path,
'strategy': strategy.shortname(),
'evalution': evaluation.shortname()
}
compressdata = {'run_info': run_info, 'folds': {k: {'quality': evalres[k]['test'].quality, 'runname': evalres[k]['test'].shortrunname} for k in evalres}}
utils.saveState([compressdata], filename, 'info')
utils.saveState([run_info, datasetdscr, evalres], filename)
# utils.convert2SED(filename)
for i in range(len(evalres)):
logger.debug(f'Evalution quality fold={i} is {evalres[i]["test"].quality}')
logger.debug(f'run finished args={args}')
def Main(argv):
strargs = str(argv)
auto_profiler.Profiler.GlobalDisable = True
parser = argparse.ArgumentParser(description='Run on datasets.')
parser.add_argument('--dataset', '-d', help=' to original datasets', type=int, default=0)
parser.add_argument('--output', '-o', help='Output folder', default='logs')
parser.add_argument('--mlstrategy', '-st', help='Strategy', type=int, default=0)
parser.add_argument('--segmentation', '-s', help='segmentation', type=int, default=-1)
parser.add_argument('--seg_params', '-sp', action='append', help='segmentation parameter')
parser.add_argument('--feature_extraction', '-f', type=int, default=0)
parser.add_argument('--classifier', type=int, default=0)
parser.add_argument('--evaluation', help='evaluation', type=int, default=0)
parser.add_argument('--comment', '-c', help='comment', default='')
#parser.add_argument('--h5py', help='HDF5 dataset folder')
args = parser.parse_args(argv)
utils.configurelogger(__file__, args.output, strargs)
import numpy
import os
os.system("taskset -a -pc 0-1000 %d >>/dev/null" % os.getpid())
run(args)
# print(args.seg_param)
if __name__ == '__main__':
import sys
strargs = str(sys.argv[1:])
Main(sys.argv[1:])
# https://stackoverflow.com/questions/39063676/how-to-boost-a-keras-based-neural-network-using-adaboost