def init(config): ut.check_n_create(config.LOG_DIR) ut.check_n_create(config.RES_DIR) file_name = config.LOG_DIR + "_" + config.ALGO_NAME + ".log" config.FOLDER_SUFFIX = config.FOLDER_SUFFIX + "_" + config.DATA_DIR logging.basicConfig(filename=file_name, filemode='w', level=logging.DEBUG) return logging.getLogger(config.ALGO_NAME)
def main(): args = Parser().get_parser().parse_args() print("=====Configurations=====\n", args) cfg = Config(args) train_percents = args.percents.split('_') folds = args.folds.split('_') outer_loop_stats = {} attention = {} gating = {} results = {} nodes = {} #Create Main directories path_prefixes = [ cfg.dataset_name, cfg.folder_suffix, cfg.data_sets.label_type ] utils.create_directory_tree(path_prefixes) for train_percent in train_percents: cfg.train_percent = train_percent path_prefix = path.join(path.join(*path_prefixes), cfg.train_percent) utils.check_n_create(path_prefix) attention[train_percent] = {} gating[train_percent] = {} results[train_percent] = {} outer_loop_stats[train_percent] = {} nodes[train_percent] = {} for fold in folds: print('Training percent: ', train_percent, ' Fold: ', fold, '---Running') cfg.train_fold = fold utils.check_n_create(path.join(path_prefix, cfg.train_fold)) cfg.create_directories(path.join(path_prefix, cfg.train_fold)) outer_loop_stats[train_percent][fold], nodes[train_percent][fold], results[train_percent][fold],\ attention[train_percent][fold], gating[train_percent][fold] = train_model(deepcopy(cfg)) print('Training percent: ', train_percent, ' Fold: ', fold, '---completed') utils.remove_directory(path_prefix) path_prefixes = [ cfg.dataset_name, cfg.folder_suffix, cfg.data_sets.label_type ] np.save(path.join(*path_prefixes, 'nodes.npy'), nodes) np.save(path.join(*path_prefixes, 'results.npy'), results) np.save(path.join(*path_prefixes, 'attentions.npy'), attention) np.save(path.join(*path_prefixes, 'gating.npy'), gating) np.save(path.join(*path_prefixes, 'outer_loop_stats.npy'), outer_loop_stats)
def create_directories(self, ext_path): self.logs_dir = path.join(ext_path, self.logs_d) self.ckpt_dir = path.join(ext_path, self.ckpt_d) # self.embed_dir= path.join(self.dataset_name, ext_path, self.embed_d) self.results_folder = path.join(ext_path, self.result_d) utils.check_n_create(self.logs_dir, overwrite=not self.retrain) utils.check_n_create(self.ckpt_dir, overwrite=not self.retrain) # self.check_n_create(self.embed_dir, overwrite=not self.retrain) utils.check_n_create(self.results_folder, overwrite=not self.retrain) self.project_path, self.walks_dir, self.fold_dir, self.label_path, self.features_path, \ self.length_path, self.project_prefix_path, self.adjmat_path = self.set_paths()
def init(config, dir_name, file_name): ut.check_n_create(dir_name) ut.check_n_create("tmp_output_files") file_name = dir_name + "_" + file_name logging.basicConfig(filename=file_name, filemode='w', level=logging.DEBUG) return logging.getLogger(algo_fn[config.TYPE])