def main(): args = parse_args() model_script = load_module(args.model_path) cfg = init_experiment(args) model, model_cfg = model_script.init_model(cfg) # prepare dataset dataset = YKDataset(window_size=cfg.window_size, dic_path=cfg.DIC_PATH) dataset_size = len(dataset) indices = list(range(dataset_size)) kf = KFold(n_splits=cfg.n_folds, shuffle=True) for train_indices, val_indices in kf.split(indices): print('t', train_indices) print('v', val_indices) train_sampler = SubsetRandomSampler(train_indices) val_sampler = SubsetRandomSampler(val_indices) trainer = Trainer(model, cfg, model_cfg, dataset, train_sampler, val_sampler, cfg.optimizer) logger.info(f'Total Epochs: {cfg.n_epochs}') for epoch in range(cfg.n_epochs): trainer.training(epoch) trainer.validation(epoch) cfg = init_experiment(args)
def main(): args = parse_args() model_script = load_module(args.model_path) cfg = init_experiment(args) model, model_cfg = model_script.init_model(cfg) # prepare dataset dataset = YKDataset(window_size=cfg.window_size, dic_path=cfg.DIC_PATH) dataset_size = len(dataset) indices = list(range(dataset_size)) split = int(np.floor(VAL_SPLIT * dataset_size)) if SHUFFLE_DATASET: np.random.seed(RANDOM_SEED) np.random.shuffle(indices) train_indices, val_indices = indices[split:], indices[:split] train_sampler = SubsetRandomSampler(train_indices) val_sampler = SubsetRandomSampler(val_indices) trainer = Trainer(model, cfg, model_cfg, dataset, train_sampler, val_sampler, cfg.optimizer) logger.info(f'Total Epochs: {cfg.n_epochs}') for epoch in range(cfg.n_epochs): trainer.training(epoch) trainer.validation(epoch)