dataset_names=(args.dataset3, ), preprocessing=False, train=False, kfold=args.kfold) valid_dataset = valid_dataset1.__add__(valid_dataset2).__add__(valid_dataset3) train_dataloader = AudioDataLoader(dataset=train_dataset, batch_size=config.experiment['batch_size'], drop_last=False, shuffle=True) valid_dataloader = AudioDataLoader(dataset=valid_dataset, batch_size=config.experiment['batch_size'], drop_last=False) # Model and Optimizer if args.model == 'cnn': model = CNN(config=config.model).to(device) elif args.model == 'crnn': model = CRNN(config=config.model).to(device) elif args.model == 'btc': model = BTC_model(config=config.model).to(device) else: raise NotImplementedError optimizer = optim.Adam(model.parameters(), lr=config.experiment['learning_rate'], weight_decay=config.experiment['weight_decay'], betas=(0.9, 0.98), eps=1e-9) # Make asset directory if not os.path.exists(os.path.join(asset_path, ckpt_path)): os.makedirs(os.path.join(asset_path, ckpt_path))
# Data loader train_dataset1 = AudioDataset(config, root_dir=config.path['root_path'], dataset_names=(args.dataset1,), num_workers=20, preprocessing=False, train=True, kfold=args.kfold) train_dataset2 = AudioDataset(config, root_dir=config.path['root_path'], dataset_names=(args.dataset2,), num_workers=20, preprocessing=False, train=True, kfold=args.kfold) train_dataset3 = AudioDataset(config, root_dir=config.path['root_path'], dataset_names=(args.dataset3,), num_workers=20, preprocessing=False, train=True, kfold=args.kfold) train_dataset = train_dataset1.__add__(train_dataset2).__add__(train_dataset3) valid_dataset1 = AudioDataset(config, root_dir=config.path['root_path'], dataset_names=(args.dataset1,), preprocessing=False, train=False, kfold=args.kfold) valid_dataset2 = AudioDataset(config, root_dir=config.path['root_path'], dataset_names=(args.dataset2,), preprocessing=False, train=False, kfold=args.kfold) valid_dataset3 = AudioDataset(config, root_dir=config.path['root_path'], dataset_names=(args.dataset3,), preprocessing=False, train=False, kfold=args.kfold) valid_dataset = valid_dataset1.__add__(valid_dataset2).__add__(valid_dataset3) train_dataloader = AudioDataLoader(dataset=train_dataset, batch_size=config.experiment['batch_size'], drop_last=False, shuffle=True) valid_dataloader = AudioDataLoader(dataset=valid_dataset, batch_size=config.experiment['batch_size'], drop_last=False) # Model and Optimizer if args.pre_model == 'cnn': pre_model = CNN(config=config.model).to(device) elif args.pre_model == 'crnn': pre_model = CRNN(config=config.model).to(device) elif args.pre_model == 'btc': pre_model = BTC_model(config=config.model).to(device) else: raise NotImplementedError if args.pre_model == 'cnn': if args.voca == False: if args.kfold == 0: load_ckpt_file_name = 'idx_0_%03d.pth.tar' load_restore_epoch = 10 else: if args.kfold == 0: load_ckpt_file_name = 'idx_1_%03d.pth.tar' load_restore_epoch = 10
valid_dataset = valid_dataset.__add__(valid_dataset2) if args.dataset3 != 'NA': train_dataset3 = AudioDataset(config, root_dir=config.path['root_path'], dataset_names=(args.dataset3,), \ num_workers=20, preprocessing=False, train=True, kfold=args.kfold) valid_dataset3 = AudioDataset(config, root_dir=config.path['root_path'], dataset_names=(args.dataset3,), preprocessing=False, train=False, kfold=args.kfold) train_dataset = train_dataset.__add__(train_dataset3) valid_dataset = valid_dataset.__add__(valid_dataset3) train_dataloader = AudioDataLoader(dataset=train_dataset, batch_size=config.experiment['batch_size'], drop_last=False, shuffle=True) valid_dataloader = AudioDataLoader(dataset=valid_dataset, batch_size=config.experiment['batch_size'], drop_last=False) # Model and Optimizer if args.model == 'cnn': model = CNN(config=config.model).to(device) elif args.model == 'crnn': model = CRNN(config=config.model).to(device) elif args.model == 'btc': model = BTC_model(config=config.model).to(device) else: raise NotImplementedError optimizer = optim.Adam(model.parameters(), lr=config.experiment['learning_rate'], weight_decay=config.experiment['weight_decay'], betas=(0.9, 0.98), eps=1e-9) # Make asset directory if not os.path.exists(os.path.join(asset_path, ckpt_path)): os.makedirs(os.path.join(asset_path, ckpt_path)) os.makedirs(os.path.join(asset_path, result_path)) # Load model if os.path.isfile(os.path.join(asset_path, ckpt_path, ckpt_file_name % restore_epoch)): checkpoint = torch.load(os.path.join(asset_path, ckpt_path, ckpt_file_name % restore_epoch))