def __init__(self, classifier_config_path): clf_cfg = Hparam(classifier_config_path) cpc_cfg = Hparam(clf_cfg.model.cpc_config_path) self.device = clf_cfg.train.device speakers_bank = pickle.load(open('templates/mean_speakers_vecs_dict.pkl', 'rb')) self.speakers, self.mean_vecs = list(speakers_bank.keys()), torch.stack(list(speakers_bank.values()), dim=0) model_cpc = CPCModel_NCE(cpc_cfg).to(clf_cfg.train.device) self.model = SpeakerClassificationModel(model_cpc, clf_cfg.model.hidden_size, 40, clf_cfg).to(clf_cfg.train.device) self.model.load_state_dict(torch.load(clf_cfg.train.checkpoints_dir + '/' + clf_cfg.train.cpc_checkpoint)) self.model.eval()
from tqdm import tqdm import os import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.data import DataLoader from torch.utils.data.sampler import SubsetRandomSampler from tensorboardX import SummaryWriter from hparams import Hparam from data.datasets import AudioDataset from GIL_model.model import GILModel from GIL_model.freezers import SimultaneousFreezer, IterativeFreezer config = Hparam('./GIL_model/config.yaml') gettime = lambda: str(dt.time(dt.now()))[:8] if not os.path.isdir('./checkpoints'): os.mkdir('./checkpoints') if __name__ == "__main__": writer = SummaryWriter() print('Extracting data') dataset = AudioDataset(config.data.path) train_ixs, test_ixs = dataset.train_test_split_ixs(config.train.test_size) train_sampler = SubsetRandomSampler(train_ixs) test_sampler = SubsetRandomSampler(test_ixs) dataloader_fabric = lambda ds, sampler: DataLoader( ds, config.train.batch_size, sampler=sampler, drop_last=True)
import os import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.data import DataLoader from tensorboardX import SummaryWriter from torch.utils.data import DataLoader from torch.utils.data.sampler import SubsetRandomSampler from hparams import Hparam from data.datasets import SpeakersDataset from CPC_model.model import CPCModel_NCE from classifier_models.speaker_model import SpeakerClassificationModel config = Hparam('./classifier_models/config.yaml') gettime = lambda: str(dt.time(dt.now()))[:8] if not os.path.isdir('./checkpoints'): os.mkdir('./checkpoints') if __name__ == "__main__": writer = SummaryWriter() print('Extracting data') dataset = SpeakersDataset(config.data.path) train_ixs, test_ixs = dataset.train_test_split_ixs(config.train.test_split) train_sampler = SubsetRandomSampler(train_ixs) test_sampler = SubsetRandomSampler(test_ixs) dataloader_fabric = lambda ds, sampler: DataLoader(
import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.data import DataLoader from tensorboardX import SummaryWriter from torch.utils.data import DataLoader from torch.utils.data.sampler import SubsetRandomSampler from hparams import Hparam from data.datasets import SpeakersDataset from GIL_model.model import GILModel from classifier_models.speaker_model import SpeakerClassificationModel from GIL_model.freezers import SimultaneousFreezer, IterativeFreezer config = Hparam('./classifier_models/config_gil.yaml') gettime = lambda: str(dt.time(dt.now()))[:8] if not os.path.isdir('./checkpoints'): os.mkdir('./checkpoints') if __name__ == "__main__": writer = SummaryWriter() print('Extracting data') dataset = SpeakersDataset(config.data.path) train_ixs, test_ixs = dataset.train_test_split_ixs(config.train.test_size) train_sampler = SubsetRandomSampler(train_ixs) test_sampler = SubsetRandomSampler(test_ixs) dataloader_fabric = lambda ds, sampler: DataLoader(
from datetime import datetime as dt from tqdm import tqdm import os import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.data import DataLoader from torch.utils.data.sampler import SubsetRandomSampler from tensorboardX import SummaryWriter from hparams import Hparam from data.datasets import AudioDataset from CPC_model.model import CPCModel_NCE config = Hparam('./CPC_model/config.yaml') gettime = lambda: str(dt.time(dt.now()))[:8] if not os.path.isdir('./checkpoints'): os.mkdir('./checkpoints') if __name__ == "__main__": writer = SummaryWriter() print('Extracting data') dataset = AudioDataset(config.data.path) train_ixs, test_ixs = dataset.train_test_split_ixs(config.train.test_size) train_sampler = SubsetRandomSampler(train_ixs) test_sampler = SubsetRandomSampler(test_ixs) dataloader_fabric = lambda ds, sampler: DataLoader( ds, config.train.batch_size, sampler=sampler, drop_last=True)