forked from eigensharks/mfcc-speaker-recognition
-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.py
20 lines (17 loc) · 744 Bytes
/
model.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import torch
from torch import nn
# Base model
class LSTMSpeakerEncoder(nn.Module):
def __init__(self, input_size, hidden_size, num_layers, embedding_size):
super(LSTMSpeakerEncoder, self).__init__()
self.lstm = nn.LSTM(
input_size, # Number of MFCC coefficients
hidden_size, # Number of hidden units in each LSTM layer
num_layers, # Number of stacked LSTM layers
batch_first=True,
)
self.fc = nn.Linear(hidden_size, embedding_size) # Change the output of the LSTM to any preffered embedding size
def forward(self, x):
_, (h_n, _) = self.lstm(x)
embedding = self.fc(h_n[-1]) # Last layer as embedding
return embedding