def get_embeddings(use_cuda, filename, model, test_frames):
    print(filename)
    input, label = read_MFB(filename)  # input size:(n_frames, n_dims)
    # feature, speaker_id

    tot_segments = math.ceil(
        len(input) /
        test_frames)  # total number of segments with 'test_frames'
    activation = 0
    with torch.no_grad():
        for i in range(tot_segments):
            # Divide the input in sub_inputs of length test_frames
            temp_input = input[i * test_frames:i * test_frames + test_frames]

            TT = ToTensorTestInput()
            temp_input = TT(temp_input)  # size:(1, 1, n_dims, n_frames)

            if use_cuda:
                temp_input = temp_input.cuda()
            temp_activation, _ = model(temp_input)
            activation += torch.sum(temp_activation, dim=0, keepdim=True)

    activation = l2_norm(activation, 10)

    return activation
示例#2
0
def get_embeddings(use_cuda, filename, model, test_frames):
    input, label= read_MFB(filename) # input size:(n_frames, n_dims)
    
    tot_segments = math.ceil(len(input)/test_frames) # total number of segments with 'test_frames' 
    activation = 0
    with torch.no_grad():
        for i in range(tot_segments):
            temp_input = input[i*test_frames:i*test_frames+test_frames]
            
            TT = ToTensorTestInput()
            temp_input = TT(temp_input) # size:(1, 1, n_dims, n_frames)
    
            if use_cuda:
                temp_input = temp_input.cuda()
            output, features, spk_embeddings = model.forward(temp_input,task='identification')
            activation += torch.sum(spk_embeddings, dim=0, keepdim=True)
    
    activation = l2_norm(activation, 1)
                
    return activation