def run(self): # Load Dataset dl = DataLoader(self.config) X, y = dl.load_data() # Train Model - No Training Required, Just KF Validation self.train(X, y)
def train(**kwargs): kwargs.update({'model': 'pcnnAtt'}) opt.parse(kwargs) if opt.use_gpu: torch.cuda.set_device(opt.gpu_id) model = getattr(models, "pcnnAtt")(opt) if opt.use_gpu: model.cuda() # loading data DataModel = getattr(dataset, opt.data + "Data") train_data = DataModel(opt.data_root, train=True) train_data_loader = DataLoader(train_data, opt.batch_size, shuffle=True, num_workers=opt.num_workers, collate_fn=collate_fn) test_data = DataModel(opt.data_root, train=False) test_data_loader = DataLoader(test_data, opt.batch_size, shuffle=False, num_workers=opt.num_workers, collate_fn=collate_fn) print('{} train data: {}; test data: {}'.format(now(), len(train_data), len(test_data))) optimizer = optim.Adadelta(model.parameters(), rho=0.95, eps=1e-6)
def _create_dataloader(self, N, identifier, extension): file = self.path + identifier file = ensure_file_extension(file, extension) if os.path.exists(file) and not self._forced_setup: dataloader = DataLoader.FromFile(file) else: print( "Could not find {} to load dataset (or forced); creating from sampler... " .format(file)) dataloader = DataLoader.FromSampler(self._rfs, N) dataloader.save(file) return dataloader
from config import Options CMD_DATA1 = "/data/zhangyi/Noisy_dataset/CHJ14_cmd-CHJ/CHJ14_cmd-CHJ-2/CHJ14_cmd-CHJ/" CMD_DATA2 = "/data/zhangyi/Noisy_dataset/CHJ14_cmd-CHJ/CHJ14_cmd-CHJ-3/CHJ14_cmd-CHJ/hp/" AISHELL_DATA = "/data/tengxiang/dataset/aishell-chj-hp/" EXTRA_DATA = "/data/tengxiang/dataset/wenzhifan/4CH/" HISF_DATA = "/data/tengxiang/dataset/hisf/cmd_input/wav/" LOG_HOME = "/data/tengxiang/aishell_hp/" # tt_data_dir = os.path.join(AISHELL_DATA, "cv") tt_data_dir = EXTRA_DATA audio_log_dir = os.path.join(EXTRA_DATA, "../v1") ckpt = "/home/teng.xiang/projects/model-ckpt/aishell_hp-sir_005_020/TasNet-se-19" # ckpt = "/data/tengxiang/aishell_hp/v0/ckpt/TasNet-se-9" # ckpt = "/home/teng.xiang/projects/model-ckpt/aishell_time-delay_cln/TasNet-se-17" if __name__ == "__main__": opt = Options().parse() if opt.gpu_num == 1: os.environ['CUDA_VISIBLE_DEVICES'] = '1' if opt.tt_data_dir is None: opt.tt_data_dir = tt_data_dir if opt.audio_log_dir is None: opt.audio_log_dir = audio_log_dir tt_data = SeparatedDataset([opt.tt_data_dir]) tt_loader = DataLoader(tt_data, opt.batch_size * opt.gpu_num) tasnet = Model(opt) tasnet.inference(tt_loader, ckpt)
if __name__ == "__main__": # load configrations # ========================================================================== opt = Options().parse() argchk(opt) # ========================================================================== if opt.stage == "tr": filepatterns = ["*mixture*.wav", "*speech*.wav"] tr_data = SeparatedDataset(data_dir_list=[opt.tr_data_dir], file_pattern_list=filepatterns) cv_data = SeparatedDataset(data_dir_list=[opt.cv_data_dir], file_pattern_list=filepatterns) tr_loader = DataLoader(tr_data, opt.batch_size * opt.gpu_num, shuffle=True) cv_loader = DataLoader(cv_data, opt.batch_size * opt.gpu_num) # pre_trained_model_path = "/data/tengxiang/tasnet/log/v0/" # ckpt = tf.train.latest_checkpoint(pre_trained_model_path) tasnet = Model(opt) tasnet.train(tr_loader, cv_loader) elif opt.stage == "tt": tt_data = SeparatedDataset([opt.tt_data_dir]) tt_loader = DataLoader(tt_data, opt.batch_size * opt.gpu_num) tasnet = Model(opt) tasnet.inference(tt_loader, opt.ckpt)