mirror of
https://github.com/wassname/TTS.git
synced 2026-09-09 11:16:00 +08:00
add batched speaker encoder inference
This commit is contained in:
@@ -2,7 +2,6 @@ import argparse
|
||||
import glob
|
||||
import os
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
from tqdm import tqdm
|
||||
|
||||
|
||||
@@ -174,15 +174,17 @@ class ResNetSpeakerEncoder(nn.Module):
|
||||
|
||||
offsets = np.linspace(0, max_len-num_frames, num=num_eval)
|
||||
|
||||
embeddings = []
|
||||
frames_batch = []
|
||||
for offset in offsets:
|
||||
offset = int(offset)
|
||||
end_offset = int(offset+num_frames)
|
||||
frames = x[:, offset:end_offset]
|
||||
embed = self.forward(frames, l2_norm=True)
|
||||
embeddings.append(embed)
|
||||
frames_batch.append(frames)
|
||||
|
||||
frames_batch = torch.cat(frames_batch, dim=0)
|
||||
embeddings = self.forward(frames_batch, l2_norm=True)
|
||||
|
||||
embeddings = torch.stack(embeddings)
|
||||
if return_mean:
|
||||
embeddings = torch.mean(embeddings, dim=0)
|
||||
embeddings = torch.mean(embeddings, dim=0, keepdim=True)
|
||||
|
||||
return embeddings
|
||||
|
||||
Reference in New Issue
Block a user