def make_train_kbs(scenario_path): ''' Create trained KBs per sub-fold ''' kbs_dic = {} cv_train = 'cv_'+scenario_path.split('/')[-1] for subdir in os.listdir(scenario_path + '/' + cv_train): if 'train_' in subdir and 'kb_' not in subdir: case_subdir = scenario_path + '/'+cv_train+'/'+subdir+'/' options = ' --discard --feat-timeout +inf ' options += '--root-path '+scenario_path+'/ ' # train scenario kb_name = case_subdir.split('/')[-1] input_args = (options + case_subdir).split(' ') input_args = [x for x in input_args if x] args,info,lims = train_scenario_mock(input_args) kbs_dic[case_subdir] = [args,info,lims] return kbs_dic
def prepare_scenario(scenario_name, tdir, number_insts): ''' Initial Train and Split ''' root_arr = os.path.realpath(__file__).split('/')[:-2] root = '/'.join(root_arr) src_path = root + '/src/' scenario_path = root + '/data/oasc_scenarios/train/' + scenario_name scenario_cv = scenario_path scenario_t = scenario_path + '/' + tdir if not os.path.exists(scenario_path): print 'Scenario Name Err on', scenario_path sys.exit() # crea cartella t if not os.path.exists(scenario_t): print 'Creating folder t' copyTrainFiles(scenario_path, tdir) # split train #comincia il train che in teoria andrebbe tolto poi print 'Check and Split Training Data ...' smart_conf = scenario_path + "/smart.txt" shouldSplit = False if not os.path.exists(smart_conf): shouldSplit = True else: with open(smart_conf, 'r') as f: first_line = f.readline() if first_line == '' or int(first_line) != number_insts: shouldSplit = True subdir = scenario_name cv_subdir = scenario_cv if not os.path.exists(cv_subdir + '/cv_' + subdir) or shouldSplit: case_subdir = cv_subdir + '/t' options = ' --discard --feat-timeout +inf ' options += '--root-path ' + scenario_path + '/ ' input_args = (options + case_subdir).split(' ') input_args = [x for x in input_args if x] kb_arg, kb_info, kb_lims = train_scenario_mock(input_args) with open(case_subdir + '/kb.args', 'w') as outfile: json.dump(kb_arg, outfile) smart_split(cv_subdir, kb_info, number_insts) if shouldSplit: with open(smart_conf, 'w') as f: f.write(str(number_insts)) return scenario_path, scenario_cv, src_path