def main(): with open('seq2seq.json', 'r') as f: conf_paths = json.load(f) train_manager = TrainManager(4) name = get_timestamp() random_seed = np.random.randint(1, int(1e5)) window = 'hourly' for fold_idx in range(5): for is_working in range(2): for input_days in range(1, 8): conf_path = np.random.choice( conf_paths[str(input_days)][str(is_working)]) with open(conf_path.replace('.h5', '.json'), 'r') as f: conf = json.load(f) conf['window'] = window conf['input_days'] = input_days conf['only_working_day'] = is_working conf['fold_idx'] = fold_idx conf['random_seed'] = random_seed # conf['verbose'] = False # conf['train_conf']['train_kwargs']['verbose'] = 0 conf['models_dir'] = os.path.join(DATASET_PATH, 'models', '2018_10_29_seq2seq', '%s_cv%i' % (name, fold_idx)) train_manager.submit(train_single_model, conf)
def main_parallel(): """ This will train 4 models in parallel using 2 gpus. """ train_manager = TrainManager(4) name = get_timestamp() random_seed = np.random.randint(1, int(1e5)) window = 'hourly' for fold_idx in range(5): for is_working in range(2): for input_days in range(1, 8): conf = _get_random_conf(input_days, is_working) conf['window'] = window conf['input_days'] = input_days conf['only_working_day'] = is_working conf['fold_idx'] = fold_idx conf['random_seed'] = random_seed conf['models_dir'] = os.path.join(DATASET_PATH, 'models', 'seq2seq', '%s_cv%i' % (name, fold_idx)) train_manager.submit(train_single_model, conf)
def main_sequential(): """ This will train one model each time (not in parallel) """ progress_bar = tqdm(desc='Training seq2seq', total=(5 * 2 * 7)) name = get_timestamp() random_seed = np.random.randint(1, int(1e5)) window = 'hourly' for fold_idx in range(5): for is_working in range(2): for input_days in range(1, 8): conf = _get_random_conf(input_days, is_working) conf['window'] = window conf['input_days'] = input_days conf['only_working_day'] = is_working conf['fold_idx'] = fold_idx conf['random_seed'] = random_seed conf['models_dir'] = os.path.join(DATASET_PATH, 'models', 'seq2seq', '%s_cv%i' % (name, fold_idx)) train_single_model(conf) progress_bar.update()
def main(): with open('frankenstein.json', 'r') as f: conf_paths = json.load(f) train_manager = TrainManager(4) name = get_timestamp() random_seed = np.random.randint(1, int(1e5)) for fold_idx in range(5): for window in ['daily', 'weekly']: for input_days in range(1, 8): conf_path = np.random.choice( conf_paths[window][str(input_days)]) with open(conf_path.replace('.h5', '.json'), 'r') as f: conf = json.load(f) conf['window'] = window conf['input_days'] = input_days conf['fold_idx'] = fold_idx conf['random_seed'] = random_seed conf['verbose'] = False conf['train_conf']['train_kwargs']['verbose'] = 0 conf['models_dir'] = os.path.join(DATASET_PATH, 'models', '2018_10_29_frankenstein', '%s_cv%i' % (name, fold_idx)) train_manager.submit(train_single_model, conf)
def main(): model_conf = { 'encoding': { 'is_day_off': [{'layer': 'Dense', 'units': 32, 'activation': 'relu'}], 'metadata_ohe': [{'layer': 'Dense', 'units': 8, 'activation': 'relu'}], 'data_trend': [{'layer': 'Dense', 'units': 16, 'activation': 'relu'}], 'metadata_days_off': [{'layer': 'Dense', 'units': 8, 'activation': 'relu'}], }, 'weights': [{'layer': 'Dense', 'units': 32, 'activation': 'relu'}, {'layer': 'Dense', 'units': 16, 'activation': 'relu'}], 'repeat_weights': False, } train_conf = { 'optimizer_kwargs': {'lr': 1e-3, 'clipvalue': 10}, 'train_kwargs': dict(batch_size=8, epochs=5000, verbose=0), 'callbacks': { 'EarlyStopping': { 'patience': 25, 'mode': 'min', 'verbose': 0, 'monitor': 'val_loss', 'min_delta': 0.0001}, 'ReduceLROnPlateau': { 'patience': 0, 'factor': 0.95, 'mode': 'min', 'verbose': 0, 'monitor': 'loss'}, 'ModelCheckpointRAM': { 'mode': 'min', 'verbose': 0, 'monitor': 'val_loss'}, }, } name = get_timestamp() print(name) conf = { 'windows': ['hourly', 'daily', 'weekly'], 'input_days': list(range(1, 8)), 'fold_idxs': list(range(5)), 'remove_inputs': ['temperature', 'temperature_normed', 'cluster_id_ohe'], 'max_workers': 8, 'verbose': False, 'models_dir': os.path.join( DATASET_PATH, 'models', '2018_10_11_architecture_exploration', name), 'train_conf': train_conf, 'model_conf': model_conf, } simple_train_manager(conf) n_models_trained = 1 while 1: model_conf = { 'encoding': { 'is_day_off': _create_layers(np.random.choice([8, 16, 32, 64])), 'metadata_ohe': _create_layers(np.random.choice([4, 8, 16])), 'data_trend': _create_layers(np.random.choice([8, 16, 32])), 'metadata_days_off': _create_layers(np.random.choice([4, 8, 16])), }, 'weights': _create_layers( np.random.choice([8, 16, 32, 64], size=np.random.randint(1, 4))), 'repeat_weights': False, } conf['model_conf'] = model_conf name = get_timestamp() print(name) print('Number of models trained: %i' % n_models_trained) n_models_trained += 1 conf['models_dir'] = os.path.join( DATASET_PATH, 'models', '2018_10_11_architecture_exploration', name) print(conf['models_dir']) simple_train_manager(conf)