Commit 3391e4f4 authored by Anthony Larcher's avatar Anthony Larcher
Browse files

iptionnal cuda

parent 83a17da7
......@@ -36,7 +36,8 @@ import importlib
# Read environment variable if it exists
SIDEKIT_CONFIG={"libsvm":True,
"mpi":False
"mpi":False,
"cuda":False
}
if 'SIDEKIT' in os.environ:
......@@ -47,7 +48,11 @@ if 'SIDEKIT' in os.environ:
SIDEKIT_CONFIG["libsvm"] = False
elif k == "mpi":
if val == "true":
SIDEKIT_CONFIG["mpi"] = True
SIDEKIT_CONFIG["mpi"] = True
if k == "cuda":
if val == "true":
SIDEKIT_CONFIG["libsvm"] = True
PARALLEL_MODULE = 'multiprocessing' # can be , threading, multiprocessing MPI is planned in the future
PARAM_TYPE = numpy.float32
......@@ -103,8 +108,6 @@ from sidekit.frontend.features import mfcc
from sidekit.frontend.features import pca_dct
from sidekit.frontend.features import shifted_delta_cepstral
from sidekit.nnet import FForwardNetwork
from sidekit.iv_scoring import cosine_scoring
from sidekit.iv_scoring import mahalanobis_scoring
from sidekit.iv_scoring import two_covariance_scoring
......@@ -149,10 +152,29 @@ if libsvm_loaded:
from sidekit.svm_training import *
CUDA = False
if SIDEKIT_CONFIG["cuda"]:
CUDA = True
if CUDA:
from sidekit.nnet import FForwardNetwork
from sidekit.nnet import kaldi_to_hdf5
from sidekit.nnet import XvectorMultiDataset
from sidekit.nnet import XvectorDataset
from sidekit.nnet import StatDataset
from sidekit.nnet import Xtractor
from sidekit.nnet import xtrain
from sidekit.nnet import extract_idmap
from sidekit.nnet import extract_parallel
if SIDEKIT_CONFIG["mpi"]:
found_mpi4py = importlib.find_loader('mpi4py') is not None
if found_mpi4py:
from sidekit.sidekit_mpi import EM_split, total_variability, extract_ivector
from sidekit.sidekit_mpi import EM_split
from sidekit.sidekit_mpi import total_variability
from sidekit.sidekit_mpi import extract_ivector
print("Import MPI")
......
......@@ -114,37 +114,6 @@ class SAD_RNN():
else:
self.model = model
def _sad_generator(self, train_list, uem_list, features_server):
"""
Internal method that generates batches of features
:param train_list:
:param uem_list:
:param features_server:
"""
batch_X = numpy.zeros((self.batch_size, self.duration, self.input_size))
batch_Y = numpy.zeros((self.batch_size, self.duration, 1))
batch_i = 0
for show in sorted(train_list.keys()):
features, _ = features_server.load(show)
labels = numpy.zeros((len(features), 1), dtype=numpy.int)
for seg in train_list[show]:
labels[seg['start']:seg['stop']] = 1
for seg in uem_list[show]:
start, stop = seg['start'], seg['stop']
for i in range(start, min(stop, len(features)) - self.duration, self.step):
batch_X[batch_i] = features[i:i + self.duration]
batch_Y[batch_i] = labels[i:i + self.duration]
batch_i += 1
if batch_i == self.batch_size:
X = torch.Tensor(batch_X)
Y = torch.Tensor(batch_Y)
yield X, Y
batch_i = 0
def _fit_batch(self, optimizer, criterion, X, Y):
"""
Internal method used to train the network
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment