Skip to content
Snippets Groups Projects
Commit 18128b27 authored by Elquintas's avatar Elquintas
Browse files

11/01/2023 - predictor function added

parent 24f2dea5
No related branches found
No related tags found
No related merge requests found
Showing
with 144 additions and 8 deletions
File added
File deleted
# PATHS # PATHS
wav_path: '../data/wavs/SPEECOMCO/' wav_path: '../data/wavs/SPEECOMCO/'
data_path: './data/' data_path: './data/'
embedding_path: './data/embeddings/ecapa/' embedding_path: './data/embeddings/xvec/'
model_path: './models/' model_path: './models/'
train_set_file: './data/TRAIN_LEC_SEGAUG_C2SI_98_ECAPA.csv' #'./data/TRAINING.txt' train_set_file: './data/TRAIN_LEC_SEGAUG_C2SI_98_XVEC.csv' #'./data/TRAINING.txt'
validation_set_file: './data/VALIDATION_LEC_SEGAUG_C2SI_10_ECAPA.csv' validation_set_file: './data/VALIDATION_LEC_SEGAUG_C2SI_10_XVEC.csv'
test_set_file: './data/TEST_DAP_UNSEGMENTED_ECAPA.csv' test_set_file: './data/TEST_DAP_UNSEGMENTED_XVEC.csv'
...@@ -21,7 +21,7 @@ dropout: 0.2 ...@@ -21,7 +21,7 @@ dropout: 0.2
# MODEL PARAMETERS # MODEL PARAMETERS
first_layer: 192 first_layer: 512
second_layer: 128 second_layer: 128
third_layer: 64 third_layer: 64
...@@ -30,4 +30,4 @@ third_layer: 64 ...@@ -30,4 +30,4 @@ third_layer: 64
# Types of embeddings supported: 'ecapa_tdnn' or 'x-vector' # Types of embeddings supported: 'ecapa_tdnn' or 'x-vector'
# ecapa_tdnn: dim = 192 (change first_layer dim) # ecapa_tdnn: dim = 192 (change first_layer dim)
# x-vector: dim = 512 (change first_layer dim) # x-vector: dim = 512 (change first_layer dim)
embedding_type: ecapa_tdnn embedding_type: x-vector
,sebastiao,Valinor,10.01.2023 13:49,file:///homelocal/sebastiao/.config/libreoffice/4;
\ No newline at end of file
,sebastiao,Valinor,10.01.2023 13:54,file:///homelocal/sebastiao/.config/libreoffice/4;
\ No newline at end of file
File added
File added
File added
File added
File added
File added
File added
File added
import yaml
import torch
import torch.nn as nn
import torch.nn.functional as F
with open("./parameters.yaml", "r") as ymlfile:
cfg = yaml.safe_load(ymlfile)
class model_embedding_snn(nn.Module):
def __init__(self):
super(model_embedding_snn,self).__init__()
self.relu = nn.ReLU()
#self.dropout = nn.Dropout2d(cfg['dropout'])
self.dropout = nn.Dropout(cfg['dropout'])
self.batch_norm1 = nn.BatchNorm1d(cfg['first_layer'])
self.batch_norm2 = nn.BatchNorm1d(cfg['second_layer'])
self.batch_norm3 = nn.BatchNorm1d(cfg['third_layer'])
self.fc1 = nn.Linear(cfg['first_layer'],cfg['second_layer'])
self.fc2 = nn.Linear(cfg['second_layer'],cfg['third_layer'])
self.fc_voix = nn.Linear(cfg['third_layer'],1)
self.fc_res = nn.Linear(cfg['third_layer'],1)
self.fc_pros = nn.Linear(cfg['third_layer'],1)
self.fc_pd = nn.Linear(cfg['third_layer'],1)
self.fc_sev = nn.Linear(cfg['third_layer'],1)
self.fc_int = nn.Linear(cfg['third_layer'],1)
def forward(self, input_embs):
x = self.batch_norm1(input_embs)
x = self.fc1(x)
x = self.dropout(x)
x = self.relu(x)
x = self.batch_norm2(x)
x = self.fc2(x)
x = self.dropout(x)
x = self.relu(x)
x = self.batch_norm3(x)
v = self.fc_voix(x)
v = self.relu(v)
r = self.fc_res(x)
r = self.relu(r)
p = self.fc_pros(x)
p = self.relu(p)
pd = self.fc_pd(x)
pd = self.relu(pd)
INT = self.fc_int(x)
INT = self.relu(INT)
SEV = self.fc_sev(x)
SEV = self.relu(SEV)
return SEV, INT, v, r, p, pd
File added
# PATHS
wav_path: '../data/wavs/SPEECOMCO/'
data_path: './data/'
embedding_path: './data/embeddings/xvec/'
model_path: './models/'
train_set_file: './data/TRAIN_LEC_SEGAUG_C2SI_98_XVEC.csv' #'./data/TRAINING.txt'
validation_set_file: './data/VALIDATION_LEC_SEGAUG_C2SI_10_XVEC.csv'
test_set_file: './data/TEST_DAP_UNSEGMENTED_XVEC.csv'
# TRAINING PARAMETERS
sampling_rate: 16000
batch_size: 8
learning_rate: 0.001
epochs: 20
dropout: 0.2
# MODEL PARAMETERS
first_layer: 512
second_layer: 128
third_layer: 64
# Types of embeddings supported: 'ecapa_tdnn' or 'x-vector'
# ecapa_tdnn: dim = 192 (change first_layer dim)
# x-vector: dim = 512 (change first_layer dim)
embedding_type: x-vector
import torch
#import yaml
import model
import torchaudio
from speechbrain.pretrained import EncoderClassifier
#with open("./configs/parameters.yaml", "r") as ymlfile:
# cfg = yaml.safe_load(ymlfile)
MODEL_PATH = './model_snn_x-vector'
class PythonPredictor():
def __init__(self):
super(PythonPredictor,self).__init__()
self.model = model.model_embedding_snn().cuda()
#self.model.load_state_dict(torch.load(cfg['model_path']+'model_snn_'\
# +cfg['embedding_type']))
self.model.load_state_dict(torch.load(MODEL_PATH))
self.model.eval()
self.emb_extractor = EncoderClassifier.from_hparams(source=\
"speechbrain/spkrec-xvect-voxceleb", savedir=\
"pretrained_models/spkrec-xvect-voxceleb")
def predict(self,wavfile):
signal, fs =torchaudio.load(wavfile)
emb = self.emb_extractor.encode_batch(signal)
emb = emb.squeeze().unsqueeze(0).cuda()
sev_,int_,v_,r_,p_,pd_=self.model(emb)
print('\nFilename: {}\n'.format(wavfile))
print('Speech Disorder Severity: {}'.format(round(sev_.item(),3)))
print('Speech Intelligibility: {}\n'.format(round(int_.item(),3)))
/homelocal/sebastiao/.cache/huggingface/hub/models--speechbrain--spkrec-xvect-voxceleb/snapshots/e2cc27f853f99bd5d539432f0cba3f124c059f71/classifier.ckpt
\ No newline at end of file
/homelocal/sebastiao/.cache/huggingface/hub/models--speechbrain--spkrec-xvect-voxceleb/snapshots/e2cc27f853f99bd5d539432f0cba3f124c059f71/embedding_model.ckpt
\ No newline at end of file
/homelocal/sebastiao/.cache/huggingface/hub/models--speechbrain--spkrec-xvect-voxceleb/snapshots/e2cc27f853f99bd5d539432f0cba3f124c059f71/hyperparams.yaml
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment