__init__.py 6.25 KB
Newer Older
Anthony Larcher's avatar
Initial  
Anthony Larcher committed
1
# -*- coding: utf-8 -*-
Anthony Larcher's avatar
Anthony Larcher committed
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#
# This file is part of SIDEKIT.
#
# SIDEKIT is a python package for speaker verification.
# Home page: http://www-lium.univ-lemans.fr/sidekit/
#
# SIDEKIT is a python package for speaker verification.
# Home page: http://www-lium.univ-lemans.fr/sidekit/
#    
# SIDEKIT is free software: you can redistribute it and/or modify
# it under the terms of the GNU LLesser General Public License as 
# published by the Free Software Foundation, either version 3 of the License, 
# or (at your option) any later version.
#
# SIDEKIT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with SIDEKIT.  If not, see <http://www.gnu.org/licenses/>.
Anthony Larcher's avatar
Initial  
Anthony Larcher committed
23
24

"""
Anthony Larcher's avatar
Anthony Larcher committed
25
Copyright 2014-2019 Anthony Larcher and Sylvain Meignier
Anthony Larcher's avatar
Anthony Larcher committed
26
"""
Anthony Larcher's avatar
Initial  
Anthony Larcher committed
27

Anthony Larcher's avatar
Anthony Larcher committed
28
29
from ctypes import *
from ctypes.util import find_library
Anthony Larcher's avatar
svm    
Anthony Larcher committed
30
import logging
Anthony Larcher's avatar
Anthony Larcher committed
31
import numpy
Anthony Larcher's avatar
Anthony Larcher committed
32
import os
Anthony Larcher's avatar
svm    
Anthony Larcher committed
33
import sys
Anthony Larcher's avatar
Anthony Larcher committed
34
import importlib
Anthony Larcher's avatar
Anthony Larcher committed
35
36
37


# Read environment variable if it exists
38
SIDEKIT_CONFIG={"libsvm":True,
Anthony Larcher's avatar
Anthony Larcher committed
39
40
                "mpi":False,
                "cuda":False
Anthony Larcher's avatar
Anthony Larcher committed
41
                }
Anthony Larcher's avatar
Anthony Larcher committed
42

Anthony Larcher's avatar
Anthony Larcher committed
43
44
45
if 'SIDEKIT' in os.environ:
    for cfg in os.environ['SIDEKIT'].split(","):
        k, val = cfg.split("=")
46
        if k == "libsvm":
Anthony Larcher's avatar
Anthony Larcher committed
47
48
           if val == "false":
                SIDEKIT_CONFIG["libsvm"] = False 
Anthony Larcher's avatar
Anthony Larcher committed
49
50
        elif k == "mpi":
            if val == "true":
Anthony Larcher's avatar
Anthony Larcher committed
51
52
53
54
55
               SIDEKIT_CONFIG["mpi"] = True
        if k == "cuda":
            if val == "true":
                SIDEKIT_CONFIG["libsvm"] = True

Anthony Larcher's avatar
Anthony Larcher committed
56

Anthony Larcher's avatar
Anthony Larcher committed
57
PARALLEL_MODULE = 'multiprocessing'  # can be , threading, multiprocessing MPI is planned in the future
Anthony Larcher's avatar
Anthony Larcher committed
58
PARAM_TYPE = numpy.float32
59
STAT_TYPE = numpy.float64  # can be numpy.float32 to speed up the computation but can lead to numerical issuess
Anthony Larcher's avatar
Anthony Larcher committed
60

Anthony Larcher's avatar
Anthony Larcher committed
61
62
63
64
65
66
67
# Import bosaris-like classes
from sidekit.bosaris import IdMap
from sidekit.bosaris import Ndx
from sidekit.bosaris import Key
from sidekit.bosaris import Scores
from sidekit.bosaris import DetPlot
from sidekit.bosaris import effective_prior
68
from sidekit.bosaris import logit_effective_prior
Anthony Larcher's avatar
Anthony Larcher committed
69
70
71
from sidekit.bosaris import fast_minDCF

# Import classes
72
from sidekit.features_extractor import FeaturesExtractor
Anthony Larcher's avatar
Anthony Larcher committed
73
74
75
from sidekit.features_server import FeaturesServer
from sidekit.mixture import Mixture
from sidekit.statserver import StatServer
Anthony Larcher's avatar
Anthony Larcher committed
76
from sidekit.factor_analyser import FactorAnalyser
Anthony Larcher's avatar
Anthony Larcher committed
77

Anthony Larcher's avatar
Anthony Larcher committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
from sidekit.frontend.io import write_pcm
from sidekit.frontend.io import read_pcm
from sidekit.frontend.io import pcmu2lin
from sidekit.frontend.io import read_sph
from sidekit.frontend.io import write_label
from sidekit.frontend.io import read_label
from sidekit.frontend.io import read_spro4
from sidekit.frontend.io import read_audio
from sidekit.frontend.io import write_spro4
from sidekit.frontend.io import read_htk
from sidekit.frontend.io import write_htk

from sidekit.frontend.vad import vad_energy
from sidekit.frontend.vad import vad_snr
from sidekit.frontend.vad import label_fusion
from sidekit.frontend.vad import speech_enhancement


from sidekit.frontend.normfeat import cms
from sidekit.frontend.normfeat import cmvn
from sidekit.frontend.normfeat import stg
from sidekit.frontend.normfeat import rasta_filt


from sidekit.frontend.features import compute_delta
from sidekit.frontend.features import framing
from sidekit.frontend.features import pre_emphasis
from sidekit.frontend.features import trfbank
from sidekit.frontend.features import mel_filter_bank
from sidekit.frontend.features import mfcc
from sidekit.frontend.features import pca_dct
from sidekit.frontend.features import shifted_delta_cepstral

Anthony Larcher's avatar
Anthony Larcher committed
111
112
113
114
115
from sidekit.iv_scoring import cosine_scoring
from sidekit.iv_scoring import mahalanobis_scoring
from sidekit.iv_scoring import two_covariance_scoring
from sidekit.iv_scoring import PLDA_scoring

Anthony Larcher's avatar
gmm ubm    
Anthony Larcher committed
116
117
from sidekit.gmm_scoring import gmm_scoring 

Anthony Larcher's avatar
JFA    
Anthony Larcher committed
118
119
from sidekit.jfa_scoring import jfa_scoring

Anthony Larcher's avatar
export    
Anthony Larcher committed
120
121
122
from sidekit.sidekit_io import write_norm_hdf5
from sidekit.sidekit_io import write_matrix_hdf5

Anthony Larcher's avatar
Anthony Larcher committed
123

Anthony Larcher's avatar
Anthony Larcher committed
124
from sidekit.sv_utils import clean_stat_server
Anthony Larcher's avatar
Anthony Larcher committed
125

Anthony Larcher's avatar
svm    
Anthony Larcher committed
126
libsvm_loaded = False
Anthony Larcher's avatar
Anthony Larcher committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
if SIDEKIT_CONFIG["libsvm"]:
    try:
        dirname = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'libsvm')
        if sys.platform == 'win32':
            libsvm = CDLL(os.path.join(dirname, r'libsvm.dll'))
            libsvm_loaded = True
        else:
            libsvm = CDLL(os.path.join(dirname, 'libsvm.so.2'))
            libsvm_loaded = True
    except:
        # For unix the prefix 'lib' is not considered.
        if find_library('svm'):
            libsvm = CDLL(find_library('svm'))
            libsvm_loaded = True
        elif find_library('libsvm'):
            libsvm = CDLL(find_library('libsvm'))
            libsvm_loaded = True
        else:
            libsvm_loaded = False
            logging.warning('WARNNG: libsvm is not installed, please refer to the' +
                            ' documentation if you intend to use SVM classifiers')
Anthony Larcher's avatar
svm    
Anthony Larcher committed
148
149
150
151
152
153

if libsvm_loaded:
    from sidekit.libsvm import *
    from sidekit.svm_scoring import *
    from sidekit.svm_training import *

Anthony Larcher's avatar
Anthony Larcher committed
154

Anthony Larcher's avatar
Anthony Larcher committed
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
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


Anthony Larcher's avatar
Anthony Larcher committed
172
173
174
if SIDEKIT_CONFIG["mpi"]:
    found_mpi4py = importlib.find_loader('mpi4py') is not None
    if found_mpi4py:
Anthony Larcher's avatar
Anthony Larcher committed
175
176
177
        from sidekit.sidekit_mpi import EM_split
        from sidekit.sidekit_mpi import total_variability
        from sidekit.sidekit_mpi import extract_ivector
Anthony Larcher's avatar
Anthony Larcher committed
178
179
180
        print("Import MPI")
        

Anthony Larcher's avatar
Anthony Larcher committed
181
__author__ = "Anthony Larcher and Sylvain Meignier"
Anthony Larcher's avatar
Anthony Larcher committed
182
__copyright__ = "Copyright 2014-2019 Anthony Larcher and Sylvain Meignier"
Anthony Larcher's avatar
Initial  
Anthony Larcher committed
183
184
185
186
187
__license__ = "LGPL"
__maintainer__ = "Anthony Larcher"
__email__ = "anthony.larcher@univ-lemans.fr"
__status__ = "Production"
__docformat__ = 'reStructuredText'
Anthony Larcher's avatar
Anthony Larcher committed
188
__version__="1.3.2"
Anthony Larcher's avatar
Initial  
Anthony Larcher committed
189

Anthony Larcher's avatar
Anthony Larcher committed
190
191
192
193
194
# __all__ = ["io",
#            "vad",
#            "normfeat",
#            "features"
#            ]