Exemplo n.º 1
0
elif args.model == 'lcnn29_mfcc':
    model = model_.lcnn_29layers_v2(n_z=args.latent_size,
                                    proj_size=len(train_dataset.speakers_list)
                                    if args.softmax != 'none' else 0,
                                    ncoef=args.ncoef,
                                    sm_type=args.softmax)
elif args.model == 'TDNN':
    model = model_.TDNN(n_z=args.latent_size,
                        proj_size=len(train_dataset.speakers_list)
                        if args.softmax != 'none' else 0,
                        ncoef=args.ncoef,
                        sm_type=args.softmax)
elif args.model == 'TDNN_multipool':
    model = model_.TDNN_multipool(n_z=args.latent_size,
                                  proj_size=len(train_dataset.speakers_list)
                                  if args.softmax != 'none' else 0,
                                  ncoef=args.ncoef,
                                  sm_type=args.softmax)
elif args.model == 'FTDNN':
    model = model_.FTDNN(n_z=args.latent_size,
                         proj_size=len(train_dataset.speakers_list)
                         if args.softmax != 'none' else 0,
                         ncoef=args.ncoef,
                         sm_type=args.softmax)

if args.pretrained_path is not None:
    ckpt = torch.load(args.pretrained_path,
                      map_location=lambda storage, loc: storage)

    try:
        model.load_state_dict(ckpt['model_state'], strict=True)
Exemplo n.º 2
0
                             if args.softmax != 'none' or args.pretrain else 0,
                             ncoef=args.ncoef,
                             sm_type=args.softmax,
                             delta=args.delta)
elif args.model == 'TDNN_mod':
    model = model_.TDNN_mod(n_z=args.latent_size,
                            proj_size=train_dataset.n_speakers
                            if args.softmax != 'none' or args.pretrain else 0,
                            ncoef=args.ncoef,
                            sm_type=args.softmax,
                            delta=args.delta)
elif args.model == 'TDNN_multipool':
    model = model_.TDNN_multipool(
        n_z=args.latent_size,
        proj_size=train_dataset.n_speakers
        if args.softmax != 'none' or args.pretrain else 0,
        ncoef=args.ncoef,
        sm_type=args.softmax,
        delta=args.delta)
elif args.model == 'transformer':
    model = model_.transformer_enc(
        n_z=args.latent_size,
        proj_size=train_dataset.n_speakers
        if args.softmax != 'none' or args.pretrain else 0,
        ncoef=args.ncoef,
        sm_type=args.softmax,
        delta=args.delta)

if args.cuda:
    model = model.to(device)
Exemplo n.º 3
0
                                    ncoef=args.ncoef,
                                    sm_type=args.softmax)
    elif args.model == 'lcnn29_mfcc':
        model = model_.lcnn_29layers_v2(n_z=args.latent_size,
                                        proj_size=len(list(
                                            labels_dict.keys())),
                                        ncoef=args.ncoef,
                                        sm_type=args.softmax)
    elif args.model == 'TDNN':
        model = model_.TDNN(n_z=args.latent_size,
                            proj_size=len(list(labels_dict.keys())),
                            ncoef=args.ncoef,
                            sm_type=args.softmax)
    elif args.model == 'TDNN_multipool':
        model = model_.TDNN_multipool(n_z=args.latent_size,
                                      proj_size=len(list(labels_dict.keys())),
                                      ncoef=args.ncoef,
                                      sm_type=args.softmax)
    elif args.model == 'FTDNN':
        model = model_.FTDNN(n_z=args.latent_size,
                             proj_size=len(list(labels_dict.keys())),
                             ncoef=args.ncoef,
                             sm_type=args.softmax)

    if args.cp_path_2 is not None:
        model_2 = type(model)(n_z=args.latent_size,
                              proj_size=len(list(labels_dict.keys())),
                              ncoef=args.ncoef,
                              sm_type=args.softmax)
        ckpt_2 = torch.load(args.cp_path_2,
                            map_location=lambda storage, loc: storage)
        model_2.load_state_dict(ckpt_2['model_state'], strict=True)
Exemplo n.º 4
0
                                    ncoef=args.ncoef)
    elif args.model == 'lcnn9_mfcc':
        model = model_.lcnn_9layers(n_z=args.latent_size,
                                    proj_size=None,
                                    ncoef=args.ncoef)
    elif args.model == 'lcnn29_mfcc':
        model = model_.lcnn_29layers_v2(n_z=args.latent_size,
                                        proj_size=None,
                                        ncoef=args.ncoef)
    elif args.model == 'TDNN':
        model = model_.TDNN(n_z=args.latent_size,
                            proj_size=None,
                            ncoef=args.ncoef)
    elif args.model == 'TDNN_multipool':
        model = model_.TDNN_multipool(n_z=args.latent_size,
                                      proj_size=None,
                                      ncoef=args.ncoef)
    elif args.model == 'FTDNN':
        model = model_.FTDNN(n_z=args.latent_size,
                             proj_size=None,
                             ncoef=args.ncoef)

    ckpt = torch.load(args.cp_path, map_location=lambda storage, loc: storage)
    model.load_state_dict(ckpt['model_state'], strict=False)

    model.eval()

    if args.cuda:
        model = model.cuda()

    scp_list = glob.glob(args.path_to_data + '*.scp')
Exemplo n.º 5
0
                                 proj_size=0,
                                 ncoef=args.ncoef,
                                 delta=args.delta)
    elif args.model == 'TDNN_aspp':
        model = model_.TDNN_aspp(n_z=args.latent_size,
                                 proj_size=0,
                                 ncoef=args.ncoef,
                                 delta=args.delta)
    elif args.model == 'TDNN_mod':
        model = model_.TDNN_mod(n_z=args.latent_size,
                                proj_size=0,
                                ncoef=args.ncoef,
                                delta=args.delta)
    elif args.model == 'TDNN_multipool':
        model = model_.TDNN_multipool(n_z=args.latent_size,
                                      proj_size=0,
                                      ncoef=args.ncoef,
                                      delta=args.delta)
    elif args.model == 'transformer':
        model = model_.transformer_enc(n_z=args.latent_size,
                                       proj_size=0,
                                       ncoef=args.ncoef,
                                       delta=args.delta)

    ckpt = torch.load(args.cp_path, map_location=lambda storage, loc: storage)
    model.load_state_dict(ckpt['model_state'], strict=False)

    model.eval()

    if args.cuda:
        model = model.to(device)
Exemplo n.º 6
0
def train(lr, l2, max_gnorm, momentum, margin, lambda_, swap, latent_size, n_frames, model, ncoef, epochs, batch_size, valid_batch_size, n_workers, cuda, train_hdf_file, valid_hdf_file, cp_path, softmax, delta, logdir):

	if cuda:
		device=get_freer_gpu()
		if args.model == 'resnet_qrnn':
			import cupy
			cupy.cuda.Device(int(str(device).split(':')[-1])).use()

	cp_name = get_file_name(cp_path)

	if args.logdir:
		from torch.utils.tensorboard import SummaryWriter
		writer = SummaryWriter(log_dir=logdir+cp_name, comment=args.model, purge_step=True)
	else:
		writer = None

	train_dataset = Loader(hdf5_name = train_hdf_file, max_nb_frames = int(n_frames), delta = delta)
	train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=batch_size, shuffle=True, num_workers=n.workers, worker_init_fn=set_np_randomseed)

	valid_dataset = Loader_valid(hdf5_name = valid_hdf_file, max_nb_frames = int(n_frames), delta = delta)
	valid_loader = torch.utils.data.DataLoader(valid_dataset, batch_size=valid_batch_size, shuffle=True, num_workers=n_workers, worker_init_fn=set_np_randomseed)

	if model == 'resnet_mfcc':
		model=model_.ResNet_mfcc(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=ncoef, sm_type=softmax, delta=delta)
	elif model == 'resnet_34':
		model=model_.ResNet_34(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=ncoef, sm_type=softmax, delta=delta)
	elif model == 'resnet_lstm':
		model=model_.ResNet_lstm(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=ncoef, sm_type=softmax, delta=delta)
	elif model == 'resnet_qrnn':
		model=model_.ResNet_qrnn(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=ncoef, sm_type=softmax, delta=delta)
	elif model == 'resnet_stats':
		model=model_.ResNet_stats(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=ncoef, sm_type=softmax, delta=delta)
	elif args.model == 'resnet_large':
		model = model_.ResNet_large(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=args.ncoef, sm_type=softmax, delta=delta)
	elif args.model == 'resnet_small':
		model = model_.ResNet_small(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=args.ncoef, sm_type=softmax, delta=delta)
	elif args.model == 'resnet_2d':
		model = model_.ResNet_2d(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=args.ncoef, sm_type=softmax, delta=delta)
	elif args.model == 'TDNN':
		model = model_.TDNN(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=args.ncoef, sm_type=softmax, delta=delta)
	elif args.model == 'TDNN_att':
		model = model_.TDNN_att(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=args.ncoef, sm_type=softmax, delta=delta)
	elif args.model == 'TDNN_multihead':
		model = model_.TDNN_multihead(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=args.ncoef, sm_type=softmax, delta=delta)
	elif args.model == 'TDNN_lstm':
		model = model_.TDNN_lstm(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=args.ncoef, sm_type=softmax, delta=delta)
	elif args.model == 'TDNN_aspp':
		model = model_.TDNN_aspp(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=args.ncoef, sm_type=softmax, delta=delta)
	elif args.model == 'TDNN_mod':
		model = model_.TDNN_mod(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=args.ncoef, sm_type=softmax, delta=delta)
	elif args.model == 'TDNN_multipool':
		model = model_.TDNN_multipool(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=args.ncoef, sm_type=softmax, delta=delta)
	elif args.model == 'transformer':
		model = model_.transformer_enc(n_z=int(latent_size), proj_size=train_dataset.n_speakers, ncoef=args.ncoef, sm_type=softmax, delta=delta)

	if cuda:
		model=model.to(device)
	else:
		device=None

	optimizer=optim.SGD(model.parameters(), lr=lr, momentum=momentum, weight_decay=l2)

	trainer=TrainLoop(model, optimizer, train_loader, valid_loader, max_gnorm=max_gnorm, margin=margin, lambda_=lambda_, verbose=-1, device=device, cp_name=cp_name, save_cp=True, checkpoint_path=cp_path, swap=swap, softmax=True, pretrain=False, mining=True, cuda=cuda, logger=writer)

	return trainer.train(n_epochs=epochs)
Exemplo n.º 7
0
if args.model == 'TDNN_lstm' or args.model == 'all':
	batch = torch.rand(3, 3 if args.delta else 1, args.ncoef, 200)
	model = model_.TDNN_lstm(n_z=args.latent_size, ncoef=args.ncoef, delta=args.delta, proj_size=10, sm_type='softmax')
	mu, emb = model.forward(batch)
	out = model.out_proj(mu, torch.ones(mu.size(0)))
	print('TDNN_lstm', mu.size(), emb.size(), out.size())
if args.model == 'TDNN_aspp' or args.model == 'all':
	batch = torch.rand(3, 3 if args.delta else 1, args.ncoef, 200)
	model = model_.TDNN_aspp(n_z=args.latent_size, ncoef=args.ncoef, delta=args.delta, proj_size=10, sm_type='softmax')
	mu, emb = model.forward(batch)
	out = model.out_proj(mu, torch.ones(mu.size(0)))
	print('TDNN_aspp', mu.size(), emb.size(), out.size())
if args.model == 'TDNN_mod' or args.model == 'all':
	batch = torch.rand(3, 3 if args.delta else 1, args.ncoef, 200)
	model = model_.TDNN_mod(n_z=args.latent_size, ncoef=args.ncoef, delta=args.delta, proj_size=10, sm_type='softmax')
	mu, emb = model.forward(batch)
	out = model.out_proj(mu, torch.ones(mu.size(0)))
	print('TDNN_mod', mu.size(), emb.size(), out.size())
if args.model == 'TDNN_multipool' or args.model == 'all':
	batch = torch.rand(3, 3 if args.delta else 1, args.ncoef, 200)
	model = model_.TDNN_multipool(n_z=args.latent_size, ncoef=args.ncoef, delta=args.delta, proj_size=10, sm_type='softmax')
	mu, emb = model.forward(batch)
	out = model.out_proj(mu, torch.ones(mu.size(0)))
	print('TDNN_multipool', mu.size(), emb.size(), out.size())
if args.model == 'transformer' or args.model == 'all':
	batch = torch.rand(3, 3 if args.delta else 1, args.ncoef, 200)
	model = model_.transformer_enc(n_z=args.latent_size, ncoef=args.ncoef, delta=args.delta, proj_size=10, sm_type='softmax')
	mu, emb = model.forward(batch)
	out = model.out_proj(mu, torch.ones(mu.size(0)))
	print('transformer', mu.size(), emb.size(), out.size())