features_server.html 112 KB
Newer Older
Anthony Larcher's avatar
Anthony Larcher committed
1

Anthony Larcher's avatar
Anthony Larcher committed
2
3
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
Anthony Larcher's avatar
Anthony Larcher committed
4

Anthony Larcher's avatar
Anthony Larcher committed
5
6
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
Anthony Larcher's avatar
Anthony Larcher committed
7
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
Anthony Larcher's avatar
Anthony Larcher committed
8
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
Anthony Larcher's avatar
doc    
Anthony Larcher committed
9
    <title>features_server &#8212; SIDEKIT  documentation</title>
Anthony Larcher's avatar
Anthony Larcher committed
10
    <link rel="stylesheet" href="../_static/sphinxdoc.css" type="text/css" />
Anthony Larcher's avatar
Anthony Larcher committed
11
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
Anthony Larcher's avatar
Anthony Larcher committed
12
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
Anthony Larcher's avatar
Anthony Larcher committed
13
14
15
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
16
    <link rel="index" title="Index" href="../genindex.html" />
Anthony Larcher's avatar
Anthony Larcher committed
17
    <link rel="search" title="Search" href="../search.html" /> 
Anthony Larcher's avatar
Anthony Larcher committed
18
  </head><body>
Anthony Larcher's avatar
Anthony Larcher committed
19
20
21
22
23
24
25
26
27
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
28
29
        <li class="nav-item nav-item-0"><a href="../index.html">SIDEKIT  documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Module code</a> &#187;</li> 
Anthony Larcher's avatar
Anthony Larcher committed
30
      </ul>
Anthony Larcher's avatar
Anthony Larcher committed
31
32
33
34
35
    </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
Anthony Larcher's avatar
Anthony Larcher committed
36
    <div class="searchformwrapper">
Anthony Larcher's avatar
Anthony Larcher committed
37
    <form class="search" action="../search.html" method="get">
Anthony Larcher's avatar
Anthony Larcher committed
38
39
      <input type="text" name="q" />
      <input type="submit" value="Go" />
Anthony Larcher's avatar
Anthony Larcher committed
40
41
42
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
Anthony Larcher's avatar
Anthony Larcher committed
43
    </div>
Anthony Larcher's avatar
Anthony Larcher committed
44
45
46
47
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
Anthony Larcher's avatar
Anthony Larcher committed
48
49
50
51
52

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
Anthony Larcher's avatar
Anthony Larcher committed
53
54
            
  <h1>Source code for features_server</h1><div class="highlight"><pre>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<span></span><span class="c1"># -*- coding: utf-8 -*-</span>
<span class="c1">#</span>
<span class="c1"># This file is part of SIDEKIT.</span>
<span class="c1">#</span>
<span class="c1"># SIDEKIT is a python package for speaker verification.</span>
<span class="c1"># Home page: http://www-lium.univ-lemans.fr/sidekit/</span>
<span class="c1">#</span>
<span class="c1"># SIDEKIT is a python package for speaker verification.</span>
<span class="c1"># Home page: http://www-lium.univ-lemans.fr/sidekit/</span>
<span class="c1">#    </span>
<span class="c1"># SIDEKIT is free software: you can redistribute it and/or modify</span>
<span class="c1"># it under the terms of the GNU LLesser General Public License as </span>
<span class="c1"># published by the Free Software Foundation, either version 3 of the License, </span>
<span class="c1"># or (at your option) any later version.</span>
<span class="c1">#</span>
<span class="c1"># SIDEKIT is distributed in the hope that it will be useful,</span>
<span class="c1"># but WITHOUT ANY WARRANTY; without even the implied warranty of</span>
<span class="c1"># MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span>
<span class="c1"># GNU Lesser General Public License for more details.</span>
<span class="c1">#</span>
<span class="c1"># You should have received a copy of the GNU Lesser General Public License</span>
<span class="c1"># along with SIDEKIT.  If not, see &lt;http://www.gnu.org/licenses/&gt;.</span>
Anthony Larcher's avatar
Anthony Larcher committed
77
78

<span class="sd">&quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
79
<span class="sd">Copyright 2014-2018 Sylvain Meignier and Anthony Larcher</span>
Anthony Larcher's avatar
Anthony Larcher committed
80
81
82
83

<span class="sd">    :mod:`features_server` provides methods to manage features</span>

<span class="sd">&quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
84
<span class="kn">import</span> <span class="nn">multiprocessing</span>
Anthony Larcher's avatar
Anthony Larcher committed
85
<span class="kn">import</span> <span class="nn">numpy</span>
Anthony Larcher's avatar
Anthony Larcher committed
86
<span class="kn">import</span> <span class="nn">logging</span>
Anthony Larcher's avatar
Anthony Larcher committed
87
88
<span class="kn">import</span> <span class="nn">h5py</span>

Anthony Larcher's avatar
doc    
Anthony Larcher committed
89
90
91
92
<span class="kn">from</span> <span class="nn">sidekit.frontend.features</span> <span class="k">import</span> <span class="n">pca_dct</span><span class="p">,</span> <span class="n">shifted_delta_cepstral</span><span class="p">,</span> <span class="n">compute_delta</span><span class="p">,</span> <span class="n">framing</span><span class="p">,</span> <span class="n">dct_basis</span>
<span class="kn">from</span> <span class="nn">sidekit.frontend.vad</span> <span class="k">import</span> <span class="n">label_fusion</span>
<span class="kn">from</span> <span class="nn">sidekit.frontend.normfeat</span> <span class="k">import</span> <span class="n">cms</span><span class="p">,</span> <span class="n">cmvn</span><span class="p">,</span> <span class="n">stg</span><span class="p">,</span> <span class="n">cep_sliding_norm</span><span class="p">,</span> <span class="n">rasta_filt</span>
<span class="kn">from</span> <span class="nn">sidekit.sv_utils</span> <span class="k">import</span> <span class="n">parse_mask</span>
Anthony Larcher's avatar
Anthony Larcher committed
93
94


Anthony Larcher's avatar
doc    
Anthony Larcher committed
95
96
<span class="n">__license__</span> <span class="o">=</span> <span class="s2">&quot;LGPL&quot;</span>
<span class="n">__author__</span> <span class="o">=</span> <span class="s2">&quot;Anthony Larcher &amp; Sylvain Meignier&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
97
<span class="n">__copyright__</span> <span class="o">=</span> <span class="s2">&quot;Copyright 2014-2018 Anthony Larcher&quot;</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
98
99
100
101
<span class="n">__maintainer__</span> <span class="o">=</span> <span class="s2">&quot;Anthony Larcher&quot;</span>
<span class="n">__email__</span> <span class="o">=</span> <span class="s2">&quot;anthony.larcher@univ-lemans.fr&quot;</span>
<span class="n">__status__</span> <span class="o">=</span> <span class="s2">&quot;Production&quot;</span>
<span class="n">__docformat__</span> <span class="o">=</span> <span class="s1">&#39;reStructuredText&#39;</span>
Anthony Larcher's avatar
Anthony Larcher committed
102
103


Anthony Larcher's avatar
Anthony Larcher committed
104
<div class="viewcode-block" id="FeaturesServer"><a class="viewcode-back" href="../api/featuresserver.html#features_server.FeaturesServer">[docs]</a><span class="k">class</span> <span class="nc">FeaturesServer</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
105
    <span class="sd">&quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
106
107
108
<span class="sd">    Management of features. FeaturesServer instances load datasets from a HDF5 files</span>
<span class="sd">    (that can be read from disk or produced by a FeaturesExtractor object)</span>
<span class="sd">    Datasets read from one or many files are concatenated and processed</span>
Anthony Larcher's avatar
Anthony Larcher committed
109
110
<span class="sd">    &quot;&quot;&quot;</span>

Anthony Larcher's avatar
Anthony Larcher committed
111
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
                 <span class="n">features_extractor</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">feature_filename_structure</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">sources</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">dataset_list</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">mask</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">feat_norm</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">global_cmvn</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">dct_pca</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">dct_pca_config</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">sdc</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
                 <span class="n">sdc_config</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">delta</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">double_delta</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">delta_filter</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">context</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">traps_dct_nb</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">rasta</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span>
                 <span class="n">keep_all_features</span><span class="o">=</span><span class="kc">True</span><span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Initialize a FeaturesServer for two cases:</span>
<span class="sd">        1. each call to load will load datasets from a single file. This mode requires to provide a dataset_list</span>
<span class="sd">        (lists of datasets to load from each file.</span>
<span class="sd">        2. each call to load will load datasets from several files (possibly several datasets from each file)</span>
<span class="sd">        and concatenate them. In this mode, you should provide a FeaturesServer for each source, thus, datasets</span>
<span class="sd">        read from each source can be post-processed independently before being concatenated with others. The dataset</span>
<span class="sd">        resulting from the concatenation from all sources is then post-processed.</span>

<span class="sd">        :param features_extractor: a FeaturesExtractor if required to extract features from audio file</span>
<span class="sd">        if None, data are loaded from an existing HDF5 file</span>
<span class="sd">        :param feature_filename_structure: structure of the filename to use to load HDF5 files</span>
<span class="sd">        :param sources: tuple of sources to load features different files (optional: for the case where datasets</span>
<span class="sd">        are loaded from several files and concatenated.</span>
<span class="sd">        :param dataset_list: string of the form &#39;[&quot;cep&quot;, &quot;fb&quot;, vad&quot;, energy&quot;, &quot;bnf&quot;]&#39; (only when loading datasets</span>
<span class="sd">        from a single file) list of datasets to load.</span>
<span class="sd">        :param mask: string of the form &#39;[1-3,10,15-20]&#39; mask to apply on the concatenated dataset</span>
<span class="sd">        to select specific components. In this example, coefficients 1,2,3,10,15,16,17,18,19,20 are kept</span>
<span class="sd">        In this example,</span>
<span class="sd">        :param feat_norm: tpye of normalization to apply as post-processing</span>
<span class="sd">        :param global_cmvn: boolean, if True, use a global mean and std when normalizing the frames</span>
<span class="sd">        :param dct_pca: if True, add temporal context by using a PCA-DCT approach</span>
<span class="sd">        :param dct_pca_config: configuration of the PCA-DCT, default is (12, 12, none)</span>
<span class="sd">        :param sdc: if True, compute shifted delta cepstra coefficients</span>
<span class="sd">        :param sdc_config: configuration to compute sdc coefficients, default is (1,3,7)</span>
<span class="sd">        :param delta: if True, append the first order derivative</span>
<span class="sd">        :param double_delta: if True, append the second order derivative</span>
<span class="sd">        :param delta_filter: coefficients of the filter used to compute delta coefficients</span>
<span class="sd">        :param context: add a left and right context, default is (0,0)</span>
<span class="sd">        :param traps_dct_nb: number of DCT coefficients to keep when computing TRAP coefficients</span>
<span class="sd">        :param rasta: if True, perform RASTA filtering</span>
<span class="sd">        :param keep_all_features: boolean, if True, keep all features, if False, keep frames according to the vad labels</span>
<span class="sd">        :return:</span>
Anthony Larcher's avatar
Anthony Larcher committed
163
<span class="sd">        &quot;&quot;&quot;</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
164
165
        <span class="bp">self</span><span class="o">.</span><span class="n">features_extractor</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">feature_filename_structure</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="si">{}</span><span class="s1">&#39;</span>
Anthony Larcher's avatar
Anthony Larcher committed
166
        <span class="bp">self</span><span class="o">.</span><span class="n">sources</span> <span class="o">=</span> <span class="p">()</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
167
168
169
170
171
172
173
174
175
        <span class="bp">self</span><span class="o">.</span><span class="n">dataset_list</span> <span class="o">=</span> <span class="kc">None</span>

        <span class="c1"># Post processing options</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">global_cmvn</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca_config</span> <span class="o">=</span> <span class="p">(</span><span class="mi">12</span><span class="p">,</span> <span class="mi">12</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">sdc</span> <span class="o">=</span> <span class="kc">False</span>
Anthony Larcher's avatar
Anthony Larcher committed
176
        <span class="bp">self</span><span class="o">.</span><span class="n">sdc_config</span> <span class="o">=</span> <span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">7</span><span class="p">)</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
177
178
        <span class="bp">self</span><span class="o">.</span><span class="n">delta</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span> <span class="o">=</span> <span class="kc">False</span>
Anthony Larcher's avatar
Anthony Larcher committed
179
180
181
        <span class="bp">self</span><span class="o">.</span><span class="n">delta_filter</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">array</span><span class="p">([</span><span class="o">.</span><span class="mi">25</span><span class="p">,</span> <span class="o">.</span><span class="mi">5</span><span class="p">,</span> <span class="o">.</span><span class="mi">25</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="o">-.</span><span class="mi">25</span><span class="p">,</span> <span class="o">-.</span><span class="mi">5</span><span class="p">,</span> <span class="o">-.</span><span class="mi">25</span><span class="p">])</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">context</span> <span class="o">=</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">traps_dct_nb</span> <span class="o">=</span> <span class="mi">0</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
182
183
        <span class="bp">self</span><span class="o">.</span><span class="n">rasta</span> <span class="o">=</span> <span class="kc">False</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">keep_all_features</span> <span class="o">=</span> <span class="kc">True</span>
Anthony Larcher's avatar
Anthony Larcher committed
184

Anthony Larcher's avatar
doc    
Anthony Larcher committed
185
        <span class="k">if</span> <span class="n">features_extractor</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
186
            <span class="bp">self</span><span class="o">.</span><span class="n">features_extractor</span> <span class="o">=</span> <span class="n">features_extractor</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
187
        <span class="k">if</span> <span class="n">feature_filename_structure</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
188
            <span class="bp">self</span><span class="o">.</span><span class="n">feature_filename_structure</span> <span class="o">=</span> <span class="n">feature_filename_structure</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
189
        <span class="k">if</span> <span class="n">sources</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
190
            <span class="bp">self</span><span class="o">.</span><span class="n">sources</span> <span class="o">=</span> <span class="n">sources</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
191
        <span class="k">if</span> <span class="n">dataset_list</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
192
            <span class="bp">self</span><span class="o">.</span><span class="n">dataset_list</span> <span class="o">=</span> <span class="n">dataset_list</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
193
        <span class="k">if</span> <span class="n">mask</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
194
            <span class="bp">self</span><span class="o">.</span><span class="n">mask</span> <span class="o">=</span> <span class="n">parse_mask</span><span class="p">(</span><span class="n">mask</span><span class="p">)</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
195
        <span class="k">if</span> <span class="n">feat_norm</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
196
            <span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="o">=</span> <span class="n">feat_norm</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
197
        <span class="k">if</span> <span class="n">global_cmvn</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
198
            <span class="bp">self</span><span class="o">.</span><span class="n">global_cmvn</span> <span class="o">=</span> <span class="n">global_cmvn</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
199
        <span class="k">if</span> <span class="n">dct_pca</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
200
            <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca</span> <span class="o">=</span> <span class="n">dct_pca</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
201
        <span class="k">if</span> <span class="n">dct_pca_config</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
202
            <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca_config</span> <span class="o">=</span> <span class="n">dct_pca_config</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
203
        <span class="k">if</span> <span class="n">sdc</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
204
            <span class="bp">self</span><span class="o">.</span><span class="n">sdc</span> <span class="o">=</span> <span class="n">sdc</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
205
        <span class="k">if</span> <span class="n">sdc_config</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
206
            <span class="bp">self</span><span class="o">.</span><span class="n">sdc_config</span> <span class="o">=</span> <span class="n">sdc_config</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
207
        <span class="k">if</span> <span class="n">delta</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
208
            <span class="bp">self</span><span class="o">.</span><span class="n">delta</span> <span class="o">=</span> <span class="n">delta</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
209
        <span class="k">if</span> <span class="n">double_delta</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
210
            <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span> <span class="o">=</span> <span class="n">double_delta</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
211
        <span class="k">if</span> <span class="n">delta_filter</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
212
            <span class="bp">self</span><span class="o">.</span><span class="n">delta_filter</span> <span class="o">=</span> <span class="n">delta_filter</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
213
        <span class="k">if</span> <span class="n">context</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
214
            <span class="bp">self</span><span class="o">.</span><span class="n">context</span> <span class="o">=</span> <span class="n">context</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
215
        <span class="k">if</span> <span class="n">traps_dct_nb</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
216
            <span class="bp">self</span><span class="o">.</span><span class="n">traps_dct_nb</span> <span class="o">=</span> <span class="n">traps_dct_nb</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
217
        <span class="k">if</span> <span class="n">rasta</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
218
            <span class="bp">self</span><span class="o">.</span><span class="n">rasta</span> <span class="o">=</span> <span class="n">rasta</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
219
        <span class="k">if</span> <span class="n">keep_all_features</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
220
            <span class="bp">self</span><span class="o">.</span><span class="n">keep_all_features</span> <span class="o">=</span> <span class="n">keep_all_features</span>
Anthony Larcher's avatar
Anthony Larcher committed
221

Anthony Larcher's avatar
doc    
Anthony Larcher committed
222
223
224
225
        <span class="bp">self</span><span class="o">.</span><span class="n">show</span> <span class="o">=</span> <span class="s1">&#39;empty&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">input_feature_filename</span> <span class="o">=</span> <span class="s1">&#39;empty&#39;</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">start_stop</span> <span class="o">=</span> <span class="p">(</span><span class="kc">None</span><span class="p">,</span> <span class="kc">None</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">previous_load</span> <span class="o">=</span> <span class="kc">None</span>
Anthony Larcher's avatar
Anthony Larcher committed
226
227
228
229

    <span class="k">def</span> <span class="nf">__repr__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>

Anthony Larcher's avatar
Anthony Larcher committed
230
<span class="sd">        :return: a string to display the object</span>
Anthony Larcher's avatar
Anthony Larcher committed
231
<span class="sd">        &quot;&quot;&quot;</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
232
233
234
235
236
237
238
239
240
        <span class="n">ch</span> <span class="o">=</span> <span class="s1">&#39;</span><span class="se">\t</span><span class="s1"> show: </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">show</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t</span><span class="s1"> input_feature_filename: </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">input_feature_filename</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t</span><span class="s1"> feature_filename_structure: </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">feature_filename_structure</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t</span><span class="s1">  </span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t</span><span class="s1">  </span><span class="se">\n\n</span><span class="s1">&#39;</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t</span><span class="s1"> Post processing options: </span><span class="se">\n</span><span class="s1">&#39;</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t\t</span><span class="s1"> mask: </span><span class="si">{}</span><span class="s1">  </span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mask</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t\t</span><span class="s1"> feat_norm: </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t\t</span><span class="s1"> dct_pca: </span><span class="si">{}</span><span class="s1">, dct_pca_config: </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">dct_pca</span><span class="p">,</span>
Anthony Larcher's avatar
Anthony Larcher committed
241
                                                               <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca_config</span><span class="p">)</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
242
        <span class="n">ch</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t\t</span><span class="s1"> sdc: </span><span class="si">{}</span><span class="s1">, sdc_config: </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">sdc</span><span class="p">,</span>
Anthony Larcher's avatar
Anthony Larcher committed
243
                                                       <span class="bp">self</span><span class="o">.</span><span class="n">sdc_config</span><span class="p">)</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
244
        <span class="n">ch</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t\t</span><span class="s1"> delta: </span><span class="si">{}</span><span class="s1">, double_delta: </span><span class="si">{}</span><span class="s1">, delta_filter: </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">delta</span><span class="p">,</span>
Anthony Larcher's avatar
Anthony Larcher committed
245
246
                                                                             <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span><span class="p">,</span>
                                                                             <span class="bp">self</span><span class="o">.</span><span class="n">delta_filter</span><span class="p">)</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
247
248
        <span class="n">ch</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t\t</span><span class="s1"> rasta: </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">rasta</span><span class="p">)</span>
        <span class="n">ch</span> <span class="o">+=</span> <span class="s1">&#39;</span><span class="se">\t\t</span><span class="s1"> keep_all_features: </span><span class="si">{}</span><span class="s1"> </span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">keep_all_features</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
249

Anthony Larcher's avatar
Anthony Larcher committed
250
251
        <span class="k">return</span> <span class="n">ch</span>

Anthony Larcher's avatar
Anthony Larcher committed
252
<div class="viewcode-block" id="FeaturesServer.post_processing"><a class="viewcode-back" href="../api/featuresserver.html#features_server.FeaturesServer.post_processing">[docs]</a>    <span class="k">def</span> <span class="nf">post_processing</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feat</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">global_mean</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">global_std</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
253
        <span class="sd">&quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
254
255
256
257
258
259
260
261
262
<span class="sd">        After cepstral coefficients, filter banks or bottleneck parameters are computed or read from file</span>
<span class="sd">        post processing is applied.</span>

<span class="sd">        :param feat: the matrix of acoustic parameters to post-process</span>
<span class="sd">        :param label: the VAD labels for the acoustic parameters</span>
<span class="sd">        :param global_mean: vector or mean to use for normalization</span>
<span class="sd">        :param global_std: vector of standard deviation to use for normalization</span>

<span class="sd">        :return: the matrix of acoustic parameters ingand their VAD labels after post-process</span>
Anthony Larcher's avatar
Anthony Larcher committed
263
<span class="sd">        &quot;&quot;&quot;</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
264
265
        <span class="c1"># Apply a mask on the features</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">mask</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
266
267
            <span class="n">feat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_mask</span><span class="p">(</span><span class="n">feat</span><span class="p">)</span>

Anthony Larcher's avatar
doc    
Anthony Larcher committed
268
        <span class="c1"># Perform RASTA filtering if required</span>
Anthony Larcher's avatar
Anthony Larcher committed
269
270
271
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">rasta</span><span class="p">:</span>
            <span class="n">feat</span><span class="p">,</span> <span class="n">label</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_rasta</span><span class="p">(</span><span class="n">feat</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span>

Anthony Larcher's avatar
doc    
Anthony Larcher committed
272
        <span class="c1"># Add temporal context</span>
Anthony Larcher's avatar
Anthony Larcher committed
273
274
275
276
277
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">delta</span> <span class="ow">or</span> <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span><span class="p">:</span>
            <span class="n">feat</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_delta_and_2delta</span><span class="p">(</span><span class="n">feat</span><span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca</span><span class="p">:</span>
            <span class="n">feat</span> <span class="o">=</span> <span class="n">pca_dct</span><span class="p">(</span><span class="n">feat</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca_config</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca_config</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="bp">self</span><span class="o">.</span><span class="n">dct_pca_config</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">sdc</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
278
            <span class="n">feat</span> <span class="o">=</span> <span class="n">shifted_delta_cepstral</span><span class="p">(</span><span class="n">feat</span><span class="p">,</span> <span class="n">d</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sdc_config</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">p</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sdc_config</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">k</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">sdc_config</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
Anthony Larcher's avatar
Anthony Larcher committed
279

Anthony Larcher's avatar
doc    
Anthony Larcher committed
280
281
        <span class="c1"># Smooth the labels and fuse the channels if more than one.</span>
        <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;Smooth the labels and fuse the channels if more than one&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
282
        <span class="n">label</span> <span class="o">=</span> <span class="n">label_fusion</span><span class="p">(</span><span class="n">label</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
283
        
Anthony Larcher's avatar
doc    
Anthony Larcher committed
284
285
286
        <span class="c1"># Normalize the data</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;no norm&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
287
288
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">_normalize</span><span class="p">(</span><span class="n">label</span><span class="p">,</span> <span class="n">feat</span><span class="p">,</span> <span class="n">global_mean</span><span class="p">,</span> <span class="n">global_std</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
289

Anthony Larcher's avatar
doc    
Anthony Larcher committed
290
        <span class="c1"># if not self.keep_all_features, only selected features and labels are kept</span>
Anthony Larcher's avatar
Anthony Larcher committed
291
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">keep_all_features</span><span class="p">:</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
292
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;no keep all&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
293
294
            <span class="n">feat</span> <span class="o">=</span> <span class="n">feat</span><span class="p">[</span><span class="n">label</span><span class="p">]</span>
            <span class="n">label</span> <span class="o">=</span> <span class="n">label</span><span class="p">[</span><span class="n">label</span><span class="p">]</span>
Anthony Larcher's avatar
Anthony Larcher committed
295

Anthony Larcher's avatar
doc    
Anthony Larcher committed
296
297
        <span class="k">return</span> <span class="n">feat</span><span class="p">,</span> <span class="n">label</span></div>

Anthony Larcher's avatar
Anthony Larcher committed
298
299
300
301
    <span class="k">def</span> <span class="nf">_mask</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cep</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Keep only the MFCC index present in the filter list</span>
<span class="sd">        :param cep: acoustic parameters to filter</span>
Anthony Larcher's avatar
Anthony Larcher committed
302

Anthony Larcher's avatar
Anthony Larcher committed
303
<span class="sd">        :return: return the list of MFCC given by filter list</span>
Anthony Larcher's avatar
Anthony Larcher committed
304
<span class="sd">        &quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
305
        <span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">mask</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
306
307
            <span class="k">raise</span> <span class="ne">Exception</span><span class="p">(</span><span class="s1">&#39;filter list is empty&#39;</span><span class="p">)</span>
        <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;applied mask&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
308
        <span class="k">return</span> <span class="n">cep</span><span class="p">[:,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mask</span><span class="p">]</span>
Anthony Larcher's avatar
Anthony Larcher committed
309

Anthony Larcher's avatar
doc    
Anthony Larcher committed
310
    <span class="k">def</span> <span class="nf">_normalize</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">cep</span><span class="p">,</span> <span class="n">global_mean</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">global_std</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
311
312
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Normalize acoustic parameters in place</span>
Anthony Larcher's avatar
Anthony Larcher committed
313

Anthony Larcher's avatar
Anthony Larcher committed
314
315
316
317
318
<span class="sd">        :param label: vad labels to use for normalization</span>
<span class="sd">        :param cep: acoustic parameters to normalize</span>
<span class="sd">        :param global_mean: mean vector to use if provided</span>
<span class="sd">        :param global_std: standard deviation vector to use if provided</span>
<span class="sd">        &quot;&quot;&quot;</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
319
320
321
        <span class="c1"># Perform feature normalization on the entire session.</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;no norm&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
322
            <span class="k">pass</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
323
324
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="o">==</span> <span class="s1">&#39;cms&#39;</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;cms norm&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
325
            <span class="n">cms</span><span class="p">(</span><span class="n">cep</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">global_mean</span><span class="p">)</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
326
327
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="o">==</span> <span class="s1">&#39;cmvn&#39;</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;cmvn norm&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
328
            <span class="n">cmvn</span><span class="p">(</span><span class="n">cep</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">global_mean</span><span class="p">,</span> <span class="n">global_std</span><span class="p">)</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
329
330
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="o">==</span> <span class="s1">&#39;stg&#39;</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;stg norm&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
331
            <span class="n">stg</span><span class="p">(</span><span class="n">cep</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">)</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
332
333
334
335
336
337
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="o">==</span> <span class="s1">&#39;cmvn_sliding&#39;</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;sliding cmvn norm&#39;</span><span class="p">)</span>
            <span class="n">cep_sliding_norm</span><span class="p">(</span><span class="n">cep</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span> <span class="n">win</span><span class="o">=</span><span class="mi">301</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">reduce</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
        <span class="k">elif</span> <span class="bp">self</span><span class="o">.</span><span class="n">feat_norm</span> <span class="o">==</span> <span class="s1">&#39;cms_sliding&#39;</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;sliding cms norm&#39;</span><span class="p">)</span>
            <span class="n">cep_sliding_norm</span><span class="p">(</span><span class="n">cep</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span> <span class="n">win</span><span class="o">=</span><span class="mi">301</span><span class="p">,</span> <span class="n">center</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span> <span class="n">reduce</span><span class="o">=</span><span class="kc">False</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
338
        <span class="k">else</span><span class="p">:</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
339
            <span class="n">logging</span><span class="o">.</span><span class="n">warning</span><span class="p">(</span><span class="s1">&#39;Wrong feature normalisation type&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
340

Anthony Larcher's avatar
Anthony Larcher committed
341
    <span class="k">def</span> <span class="nf">_delta_and_2delta</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cep</span><span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
342
        <span class="sd">&quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
343
344
345
346
<span class="sd">        Add deltas and double deltas.</span>
<span class="sd">        :param cep: a matrix of cepstral cefficients</span>

<span class="sd">        :return: the cepstral coefficient stacked with deltas and double deltas</span>
Anthony Larcher's avatar
Anthony Larcher committed
347
<span class="sd">        &quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
348
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">delta</span><span class="p">:</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
349
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;add delta&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
350
351
352
            <span class="n">delta</span> <span class="o">=</span> <span class="n">compute_delta</span><span class="p">(</span><span class="n">cep</span><span class="p">,</span> <span class="n">filt</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">delta_filter</span><span class="p">)</span>
            <span class="n">cep</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">column_stack</span><span class="p">((</span><span class="n">cep</span><span class="p">,</span> <span class="n">delta</span><span class="p">))</span>
            <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">double_delta</span><span class="p">:</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
353
                <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;add delta delta&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
354
355
356
                <span class="n">double_delta</span> <span class="o">=</span> <span class="n">compute_delta</span><span class="p">(</span><span class="n">delta</span><span class="p">,</span> <span class="n">filt</span><span class="o">=</span><span class="bp">self</span><span class="o">.</span><span class="n">delta_filter</span><span class="p">)</span>
                <span class="n">cep</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">column_stack</span><span class="p">((</span><span class="n">cep</span><span class="p">,</span> <span class="n">double_delta</span><span class="p">))</span>
        <span class="k">return</span> <span class="n">cep</span>
Anthony Larcher's avatar
Anthony Larcher committed
357
358
359
360
361
362
363
364

    <span class="k">def</span> <span class="nf">_rasta</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">cep</span><span class="p">,</span> <span class="n">label</span><span class="p">):</span>
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Performs RASTA filtering if required.</span>
<span class="sd">        The two first frames are copied from the third to keep</span>
<span class="sd">        the length consistent</span>
<span class="sd">        !!! if vad is None: label[] is empty</span>

Anthony Larcher's avatar
Anthony Larcher committed
365
366
<span class="sd">        :param cep: the acoustic features to filter</span>
<span class="sd">        :param label: the VAD label</span>
Anthony Larcher's avatar
Anthony Larcher committed
367
368
369
<span class="sd">        :return:</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">rasta</span><span class="p">:</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
370
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;perform RASTA </span><span class="si">%s</span><span class="s1">&#39;</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">rasta</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
371
372
373
374
375
            <span class="n">cep</span> <span class="o">=</span> <span class="n">rasta_filt</span><span class="p">(</span><span class="n">cep</span><span class="p">)</span>
            <span class="n">cep</span><span class="p">[:</span><span class="mi">2</span><span class="p">,</span> <span class="p">:]</span> <span class="o">=</span> <span class="n">cep</span><span class="p">[</span><span class="mi">2</span><span class="p">,</span> <span class="p">:]</span>
            <span class="n">label</span><span class="p">[:</span><span class="mi">2</span><span class="p">]</span> <span class="o">=</span> <span class="n">label</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
        <span class="k">return</span> <span class="n">cep</span><span class="p">,</span> <span class="n">label</span>

Anthony Larcher's avatar
Anthony Larcher committed
376
<div class="viewcode-block" id="FeaturesServer.get_context"><a class="viewcode-back" href="../api/featuresserver.html#features_server.FeaturesServer.get_context">[docs]</a>    <span class="k">def</span> <span class="nf">get_context</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feat</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
377
        <span class="sd">&quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
378
379
<span class="sd">        Add a left annd right context to each frame.</span>
<span class="sd">        First and last frames are duplicated to provide context at the begining and at the end</span>
Anthony Larcher's avatar
Anthony Larcher committed
380

Anthony Larcher's avatar
Anthony Larcher committed
381
382
383
384
<span class="sd">        :param feat: sequence of feature frames (one fame per line)</span>
<span class="sd">        :param start: index of the first frame of the selected segment</span>
<span class="sd">        :param stop: index of the last frame of the selected segment</span>
<span class="sd">        :param label: vad label if available</span>
Anthony Larcher's avatar
Anthony Larcher committed
385

Anthony Larcher's avatar
Anthony Larcher committed
386
<span class="sd">        :return: a sequence of frames with their left and right context</span>
Anthony Larcher's avatar
Anthony Larcher committed
387
<span class="sd">        &quot;&quot;&quot;</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
388
        <span class="k">if</span> <span class="n">start</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
389
            <span class="n">start</span> <span class="o">=</span> <span class="mi">0</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
390
        <span class="k">if</span> <span class="n">stop</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
391
392
393
394
395
            <span class="n">stop</span> <span class="o">=</span> <span class="n">feat</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
        <span class="n">context_feat</span> <span class="o">=</span> <span class="n">framing</span><span class="p">(</span>
            <span class="n">numpy</span><span class="o">.</span><span class="n">pad</span><span class="p">(</span><span class="n">feat</span><span class="p">,</span>
                      <span class="p">((</span><span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">start</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="nb">max</span><span class="p">(</span><span class="n">stop</span> <span class="o">-</span> <span class="n">feat</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span>
                       <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
396
                      <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;edge&#39;</span><span class="p">)[</span><span class="n">start</span> <span class="o">-</span> <span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">start</span><span class="p">,</span> <span class="mi">0</span><span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
397
            <span class="n">stop</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">-</span> <span class="n">start</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">:],</span> <span class="n">win_size</span><span class="o">=</span><span class="mi">1</span><span class="o">+</span><span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
398
399
        <span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="p">(</span><span class="mi">1</span><span class="o">+</span><span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">))</span> <span class="o">*</span> <span class="n">feat</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">1</span><span class="p">])</span>

Anthony Larcher's avatar
doc    
Anthony Larcher committed
400
        <span class="k">if</span> <span class="n">label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
401
            <span class="n">context_label</span> <span class="o">=</span> <span class="n">label</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="n">stop</span><span class="p">]</span>
Anthony Larcher's avatar
Anthony Larcher committed
402
        <span class="k">else</span><span class="p">:</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
403
            <span class="n">context_label</span> <span class="o">=</span> <span class="kc">None</span>
Anthony Larcher's avatar
Anthony Larcher committed
404

Anthony Larcher's avatar
doc    
Anthony Larcher committed
405
406
        <span class="k">return</span> <span class="n">context_feat</span><span class="p">,</span> <span class="n">context_label</span></div>

Anthony Larcher's avatar
Anthony Larcher committed
407
<div class="viewcode-block" id="FeaturesServer.get_traps"><a class="viewcode-back" href="../api/featuresserver.html#features_server.FeaturesServer.get_traps">[docs]</a>    <span class="k">def</span> <span class="nf">get_traps</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">feat</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
408
        <span class="sd">&quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
409
410
411
412
413
414
415
416
417
<span class="sd">        Compute TRAP parameters. The input frames are concatenated to add their left and right context,</span>
<span class="sd">        a Hamming window is applied and a DCT reduces the dimensionality of the resulting vector.</span>

<span class="sd">        :param feat: input acoustic parameters to process</span>
<span class="sd">        :param start: index of the first frame of the selected segment</span>
<span class="sd">        :param stop: index of the last frame of the selected segment</span>
<span class="sd">        :param label: vad label if available</span>

<span class="sd">        :return: a sequence of TRAP parameters</span>
Anthony Larcher's avatar
Anthony Larcher committed
418
419
<span class="sd">        &quot;&quot;&quot;</span>

Anthony Larcher's avatar
doc    
Anthony Larcher committed
420
        <span class="k">if</span> <span class="n">start</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
421
            <span class="n">start</span> <span class="o">=</span> <span class="mi">0</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
422
        <span class="k">if</span> <span class="n">stop</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
423
424
425
426
427
428
            <span class="n">stop</span> <span class="o">=</span> <span class="n">feat</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="n">context_feat</span> <span class="o">=</span> <span class="n">framing</span><span class="p">(</span>
            <span class="n">numpy</span><span class="o">.</span><span class="n">pad</span><span class="p">(</span>
                      <span class="n">feat</span><span class="p">,</span> 
                      <span class="p">((</span><span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">start</span><span class="p">,</span> <span class="n">stop</span> <span class="o">-</span> <span class="n">feat</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="mi">1</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
429
                      <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;edge&#39;</span>
Anthony Larcher's avatar
Anthony Larcher committed
430
431
                      <span class="p">)[</span><span class="n">start</span><span class="o">-</span><span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span>
                        <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">start</span><span class="p">,</span> <span class="mi">0</span><span class="p">):</span><span class="n">stop</span> <span class="o">+</span> <span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="nb">max</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">-</span><span class="n">start</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span> <span class="p">:],</span>
Anthony Larcher's avatar
Anthony Larcher committed
432
433
            <span class="n">win_size</span><span class="o">=</span><span class="mi">1</span><span class="o">+</span><span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">)</span>
        <span class="p">)</span><span class="o">.</span><span class="n">transpose</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
434
435
        <span class="n">hamming_dct</span> <span class="o">=</span> <span class="p">(</span><span class="n">dct_basis</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">traps_dct_nb</span><span class="p">,</span> <span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">)</span> <span class="o">*</span>
                       <span class="n">numpy</span><span class="o">.</span><span class="n">hamming</span><span class="p">(</span><span class="nb">sum</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">context</span><span class="p">)</span> <span class="o">+</span> <span class="mi">1</span><span class="p">))</span><span class="o">.</span><span class="n">T</span>
Anthony Larcher's avatar
Anthony Larcher committed
436

Anthony Larcher's avatar
doc    
Anthony Larcher committed
437
        <span class="k">if</span> <span class="n">label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
438
439
            <span class="n">context_label</span> <span class="o">=</span> <span class="n">label</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="n">stop</span><span class="p">]</span>
        <span class="k">else</span><span class="p">:</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
440
            <span class="n">context_label</span> <span class="o">=</span> <span class="kc">None</span>
Anthony Larcher's avatar
Anthony Larcher committed
441

Anthony Larcher's avatar
Anthony Larcher committed
442
443
444
        <span class="k">return</span> <span class="n">numpy</span><span class="o">.</span><span class="n">dot</span><span class="p">(</span>
            <span class="n">context_feat</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="n">hamming_dct</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
            <span class="n">hamming_dct</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
445
446
        <span class="p">)</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">context_feat</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="o">-</span><span class="mi">1</span><span class="p">),</span> <span class="n">context_label</span></div>

Anthony Larcher's avatar
Anthony Larcher committed
447
<div class="viewcode-block" id="FeaturesServer.load"><a class="viewcode-back" href="../api/featuresserver.html#features_server.FeaturesServer.load">[docs]</a>    <span class="k">def</span> <span class="nf">load</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">input_feature_filename</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
448
        <span class="sd">&quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
449
<span class="sd">        Depending of the setting of the FeaturesServer, can either:</span>
Anthony Larcher's avatar
Anthony Larcher committed
450

Anthony Larcher's avatar
Anthony Larcher committed
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
<span class="sd">        1. Get the datasets from a single HDF5 file</span>
<span class="sd">            The HDF5 file is loaded from disk or processed on the fly</span>
<span class="sd">            via the FeaturesExtractor of the current FeaturesServer</span>

<span class="sd">        2. Load datasets from multiple input HDF5 files. The datasets are post-processed separately, then concatenated</span>
<span class="sd">            and post-process</span>

<span class="sd">        :param show: ID of the show to load (should be the same for each HDF5 file to read from)</span>
<span class="sd">        :param channel: audio channel index in case the parameters are extracted from an audio file</span>
<span class="sd">        :param input_feature_filename: name of the input feature file in case it is independent from the ID of the show</span>
<span class="sd">        :param label: vad labels</span>
<span class="sd">        :param start: index of the first frame of the selected segment</span>
<span class="sd">        :param stop: index of the last frame of the selected segment</span>

<span class="sd">        :return: acoustic parameters and their vad labels</span>
Anthony Larcher's avatar
Anthony Larcher committed
466
<span class="sd">        &quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
467

Anthony Larcher's avatar
doc    
Anthony Larcher committed
468
469
470
        <span class="c1"># In case the name of the input file does not include the ID of the show</span>
        <span class="c1"># (i.e., feature_filename_structure does not include {})</span>
        <span class="c1"># self.audio_filename_structure is updated to use the input_feature_filename</span>
Anthony Larcher's avatar
Anthony Larcher committed
471
472
473
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">show</span> <span class="o">==</span> <span class="n">show</span> \
                <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">input_feature_filename</span> <span class="o">==</span> <span class="n">input_feature_filename</span>\
                <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">start_stop</span> <span class="o">==</span> <span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">stop</span><span class="p">)</span>  \
Anthony Larcher's avatar
doc    
Anthony Larcher committed
474
475
                <span class="ow">and</span> <span class="bp">self</span><span class="o">.</span><span class="n">previous_load</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">logging</span><span class="o">.</span><span class="n">debug</span><span class="p">(</span><span class="s1">&#39;return previous load&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
476
477
478
479
480
            <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">previous_load</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">show</span> <span class="o">=</span> <span class="n">show</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">input_feature_filename</span> <span class="o">=</span> <span class="n">input_feature_filename</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">start_stop</span> <span class="o">=</span> <span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="n">stop</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
481
        
Anthony Larcher's avatar
doc    
Anthony Larcher committed
482
483
        <span class="n">feature_filename</span> <span class="o">=</span> <span class="kc">None</span>
        <span class="k">if</span> <span class="n">input_feature_filename</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
484
485
486
            <span class="bp">self</span><span class="o">.</span><span class="n">feature_filename_structure</span> <span class="o">=</span> <span class="n">input_feature_filename</span>
            <span class="n">feature_filename</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">feature_filename_structure</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">show</span><span class="p">)</span>

Anthony Larcher's avatar
doc    
Anthony Larcher committed
487
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">dataset_list</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
488
489
490
491
492
            <span class="bp">self</span><span class="o">.</span><span class="n">previous_load</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_features</span><span class="p">(</span><span class="n">show</span><span class="p">,</span>
                                                   <span class="n">channel</span><span class="o">=</span><span class="n">channel</span><span class="p">,</span>
                                                   <span class="n">input_feature_filename</span><span class="o">=</span><span class="n">feature_filename</span><span class="p">,</span>
                                                   <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
                                                   <span class="n">start</span><span class="o">=</span><span class="n">start</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="n">stop</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
493
        <span class="k">else</span><span class="p">:</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
494
            <span class="n">logging</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Extract tandem features from multiple sources&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
495
496
497
498
            <span class="bp">self</span><span class="o">.</span><span class="n">previous_load</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">get_tandem_features</span><span class="p">(</span><span class="n">show</span><span class="p">,</span>
                                                          <span class="n">channel</span><span class="o">=</span><span class="n">channel</span><span class="p">,</span>
                                                          <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span>
                                                          <span class="n">start</span><span class="o">=</span><span class="n">start</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="n">stop</span><span class="p">)</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
499
500
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">previous_load</span></div>

Anthony Larcher's avatar
Anthony Larcher committed
501
<div class="viewcode-block" id="FeaturesServer.get_features"><a class="viewcode-back" href="../api/featuresserver.html#features_server.FeaturesServer.get_features">[docs]</a>    <span class="k">def</span> <span class="nf">get_features</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">input_feature_filename</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
502
        <span class="sd">&quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
503
504
505
506
507
508
509
510
511
512
513
514
<span class="sd">        Get the datasets from a single HDF5 file</span>
<span class="sd">        The HDF5 file is loaded from disk or processed on the fly</span>
<span class="sd">        via the FeaturesExtractor of the current FeaturesServer</span>

<span class="sd">        :param show: ID of the show</span>
<span class="sd">        :param channel: index of the channel to read</span>
<span class="sd">        :param input_feature_filename: name of the input file in case it does not include the ID of the show</span>
<span class="sd">        :param label: vad labels</span>
<span class="sd">        :param start: index of the first frame of the selected segment</span>
<span class="sd">        :param stop: index of the last frame of the selected segment</span>

<span class="sd">        :return: acoustic parameters and their vad labels</span>
Anthony Larcher's avatar
Anthony Larcher committed
515
516
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="sd">&quot;&quot;&quot;</span>
Anthony Larcher's avatar
Anthony Larcher committed
517
518
519
<span class="sd">        Si le nom du fichier d&#39;entrée est totalement indépendant du show</span>
<span class="sd">        -&gt; si feature_filename_structure ne contient pas &quot;{}&quot;</span>
<span class="sd">        on peut mettre à jour: self.audio_filename_structure pour entrer directement le nom du fichier de feature</span>
Anthony Larcher's avatar
Anthony Larcher committed
520
<span class="sd">        &quot;&quot;&quot;</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
521
        <span class="k">if</span> <span class="n">input_feature_filename</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
522
523
            <span class="bp">self</span><span class="o">.</span><span class="n">feature_filename_structure</span> <span class="o">=</span> <span class="n">input_feature_filename</span>

Anthony Larcher's avatar
doc    
Anthony Larcher committed
524
525
526
        <span class="c1"># If no extractor for this source, open hdf5 file and return handler</span>
        <span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">features_extractor</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">h5f</span> <span class="o">=</span> <span class="n">h5py</span><span class="o">.</span><span class="n">File</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">feature_filename_structure</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">show</span><span class="p">),</span> <span class="s2">&quot;r&quot;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
527

Anthony Larcher's avatar
doc    
Anthony Larcher committed
528
        <span class="c1"># If an extractor is provided for this source, extract features and return an hdf5 handler</span>
Anthony Larcher's avatar
Anthony Larcher committed
529
530
531
        <span class="k">else</span><span class="p">:</span>
            <span class="n">h5f</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">features_extractor</span><span class="o">.</span><span class="n">extract</span><span class="p">(</span><span class="n">show</span><span class="p">,</span> <span class="n">channel</span><span class="p">,</span> <span class="n">input_audio_filename</span><span class="o">=</span><span class="n">input_feature_filename</span><span class="p">)</span>

Anthony Larcher's avatar
doc    
Anthony Larcher committed
532
        <span class="c1"># Get the selected segment</span>
Anthony Larcher's avatar
Anthony Larcher committed
533
        <span class="n">dataset_length</span> <span class="o">=</span> <span class="n">h5f</span><span class="p">[</span><span class="n">show</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span> <span class="o">+</span> <span class="nb">next</span><span class="p">(</span><span class="n">h5f</span><span class="p">[</span><span class="n">show</span><span class="p">]</span><span class="o">.</span><span class="fm">__iter__</span><span class="p">())]</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
534
535
        <span class="c1"># Deal with the case where start &lt; 0 or stop &gt; feat.shape[0]</span>
        <span class="k">if</span> <span class="n">start</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
536
537
538
539
            <span class="n">start</span> <span class="o">=</span> <span class="mi">0</span>
        <span class="n">pad_begining</span> <span class="o">=</span> <span class="o">-</span><span class="n">start</span> <span class="k">if</span> <span class="n">start</span> <span class="o">&lt;</span> <span class="mi">0</span> <span class="k">else</span> <span class="mi">0</span>
        <span class="n">start</span> <span class="o">=</span> <span class="nb">max</span><span class="p">(</span><span class="n">start</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>

Anthony Larcher's avatar
doc    
Anthony Larcher committed
540
        <span class="k">if</span> <span class="n">stop</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
Anthony Larcher's avatar
Anthony Larcher committed
541
542
543
544
            <span class="n">stop</span> <span class="o">=</span> <span class="n">dataset_length</span>
        <span class="n">pad_end</span> <span class="o">=</span> <span class="n">stop</span> <span class="o">-</span> <span class="n">dataset_length</span> <span class="k">if</span> <span class="n">stop</span> <span class="o">&gt;</span> <span class="n">dataset_length</span> <span class="k">else</span> <span class="mi">0</span>
        <span class="n">stop</span> <span class="o">=</span> <span class="nb">min</span><span class="p">(</span><span class="n">stop</span><span class="p">,</span> <span class="n">dataset_length</span><span class="p">)</span>

Anthony Larcher's avatar
doc    
Anthony Larcher committed
545
        <span class="n">global_cmvn</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">global_cmvn</span> <span class="ow">and</span> <span class="ow">not</span> <span class="p">(</span><span class="n">start</span> <span class="ow">is</span> <span class="kc">None</span> <span class="ow">or</span> <span class="n">stop</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
546

Anthony Larcher's avatar
doc    
Anthony Larcher committed
547
548
        <span class="c1"># Get the data between start and stop</span>
        <span class="c1"># Concatenate all required datasets</span>
Anthony Larcher's avatar
Anthony Larcher committed
549
550
551
        <span class="n">feat</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">global_mean</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="n">global_std</span> <span class="o">=</span> <span class="p">[]</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
        <span class="k">if</span> <span class="s2">&quot;energy&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dataset_list</span><span class="p">:</span>
            <span class="n">feat</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">h5f</span><span class="p">[</span><span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;energy&quot;</span><span class="p">))]</span><span class="o">.</span><span class="n">value</span><span class="p">[</span><span class="n">start</span><span class="p">:</span><span class="n">stop</span><span class="p">,</span> <span class="n">numpy</span><span class="o">.</span><span class="n">newaxis</span><span class="p">])</span>
            <span class="n">global_mean</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">h5f</span><span class="p">[</span><span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;energy_mean&quot;</span><span class="p">))]</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
            <span class="n">global_std</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">h5f</span><span class="p">[</span><span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;energy_std&quot;</span><span class="p">))]</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
        <span class="k">if</span> <span class="s2">&quot;cep&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dataset_list</span><span class="p">:</span>
            <span class="n">feat</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">h5f</span><span class="p">[</span><span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;cep&quot;</span><span class="p">))][</span><span class="n">start</span><span class="p">:</span><span class="n">stop</span><span class="p">,</span> <span class="p">:])</span>
            <span class="n">global_mean</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">h5f</span><span class="p">[</span><span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;cep_mean&quot;</span><span class="p">))]</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
            <span class="n">global_std</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">h5f</span><span class="p">[</span><span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;cep_std&quot;</span><span class="p">))]</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
        <span class="k">if</span> <span class="s2">&quot;fb&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dataset_list</span><span class="p">:</span>
            <span class="n">feat</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">h5f</span><span class="p">[</span><span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;fb&quot;</span><span class="p">))][</span><span class="n">start</span><span class="p">:</span><span class="n">stop</span><span class="p">,</span> <span class="p">:])</span>
            <span class="n">global_mean</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">h5f</span><span class="p">[</span><span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;fb_mean&quot;</span><span class="p">))]</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
            <span class="n">global_std</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">h5f</span><span class="p">[</span><span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;fb_std&quot;</span><span class="p">))]</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
        <span class="k">if</span> <span class="s2">&quot;bnf&quot;</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">dataset_list</span><span class="p">:</span>
            <span class="n">feat</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">h5f</span><span class="p">[</span><span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;bnf&quot;</span><span class="p">))][</span><span class="n">start</span><span class="p">:</span><span class="n">stop</span><span class="p">,</span> <span class="p">:])</span>
            <span class="n">global_mean</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">h5f</span><span class="p">[</span><span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;bnf_mean&quot;</span><span class="p">))]</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
            <span class="n">global_std</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">h5f</span><span class="p">[</span><span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;bnf_std&quot;</span><span class="p">))]</span><span class="o">.</span><span class="n">value</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
568
569
570
571
        <span class="n">feat</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">hstack</span><span class="p">(</span><span class="n">feat</span><span class="p">)</span>
        <span class="n">global_mean</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">hstack</span><span class="p">(</span><span class="n">global_mean</span><span class="p">)</span>
        <span class="n">global_std</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">hstack</span><span class="p">(</span><span class="n">global_std</span><span class="p">)</span>

Anthony Larcher's avatar
doc    
Anthony Larcher committed
572
573
574
        <span class="k">if</span> <span class="n">label</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="k">if</span> <span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;vad&quot;</span><span class="p">))</span> <span class="ow">in</span> <span class="n">h5f</span><span class="p">:</span>
                <span class="n">label</span> <span class="o">=</span> <span class="n">h5f</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="o">.</span><span class="n">join</span><span class="p">((</span><span class="n">show</span><span class="p">,</span> <span class="s2">&quot;vad&quot;</span><span class="p">)))</span><span class="o">.</span><span class="n">value</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s1">&#39;bool&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">squeeze</span><span class="p">()[</span><span class="n">start</span><span class="p">:</span><span class="n">stop</span><span class="p">]</span>
Anthony Larcher's avatar
Anthony Larcher committed
575
            <span class="k">else</span><span class="p">:</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
576
577
578
579
                <span class="n">label</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">feat</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;bool&#39;</span><span class="p">)</span>
        <span class="c1"># Pad the segment if needed</span>
        <span class="n">feat</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">pad</span><span class="p">(</span><span class="n">feat</span><span class="p">,</span> <span class="p">((</span><span class="n">pad_begining</span><span class="p">,</span> <span class="n">pad_end</span><span class="p">),</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;edge&#39;</span><span class="p">)</span>
        <span class="n">label</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">pad</span><span class="p">(</span><span class="n">label</span><span class="p">,</span> <span class="p">(</span><span class="n">pad_begining</span><span class="p">,</span> <span class="n">pad_end</span><span class="p">),</span> <span class="n">mode</span><span class="o">=</span><span class="s1">&#39;edge&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
580
581
582
        <span class="n">stop</span> <span class="o">+=</span> <span class="n">pad_begining</span> <span class="o">+</span> <span class="n">pad_end</span>

        <span class="n">h5f</span><span class="o">.</span><span class="n">close</span><span class="p">()</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
583
        <span class="c1"># Post-process the features and return the features and vad label</span>
Anthony Larcher's avatar
Anthony Larcher committed
584
585
586
587
588
        <span class="k">if</span> <span class="n">global_cmvn</span><span class="p">:</span>
            <span class="n">feat</span><span class="p">,</span> <span class="n">label</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">post_processing</span><span class="p">(</span><span class="n">feat</span><span class="p">,</span> <span class="n">label</span><span class="p">,</span> <span class="n">global_mean</span><span class="p">,</span> <span class="n">global_std</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="n">feat</span><span class="p">,</span> <span class="n">label</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">post_processing</span><span class="p">(</span><span class="n">feat</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span>

Anthony Larcher's avatar
doc    
Anthony Larcher committed
589
590
        <span class="k">return</span> <span class="n">feat</span><span class="p">,</span> <span class="n">label</span></div>

Anthony Larcher's avatar
Anthony Larcher committed
591
<div class="viewcode-block" id="FeaturesServer.get_tandem_features"><a class="viewcode-back" href="../api/featuresserver.html#features_server.FeaturesServer.get_tandem_features">[docs]</a>    <span class="k">def</span> <span class="nf">get_tandem_features</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
592
593
594
595
596
597
598
599
600
601
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Read acoustic parameters from multiple HDF5 files (from disk or extracted by FeaturesExtractor objects).</span>

<span class="sd">        :param show: Id of the show</span>
<span class="sd">        :param channel: index of the channel</span>
<span class="sd">        :param label: vad labels</span>
<span class="sd">        :param start: index of the first frame of the selected segment</span>
<span class="sd">        :param stop: index of the last frame of the selected segment</span>

<span class="sd">        :return: acoustic parameters and their vad labels</span>
Anthony Larcher's avatar
Anthony Larcher committed
602
<span class="sd">        &quot;&quot;&quot;</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
603
        <span class="c1"># Each source has its own sources (including subserver) that provides features and label</span>
Anthony Larcher's avatar
Anthony Larcher committed
604
605
        <span class="n">features</span> <span class="o">=</span> <span class="p">[]</span>
        <span class="k">for</span> <span class="n">features_server</span><span class="p">,</span> <span class="n">get_vad</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">sources</span><span class="p">:</span>
Anthony Larcher's avatar
doc    
Anthony Larcher committed
606
            <span class="c1"># Get features from this source</span>
Anthony Larcher's avatar
Anthony Larcher committed
607
608
609
610
            <span class="n">feat</span><span class="p">,</span> <span class="n">lbl</span> <span class="o">=</span> <span class="n">features_server</span><span class="o">.</span><span class="n">get_features</span><span class="p">(</span><span class="n">show</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="n">channel</span><span class="p">,</span> <span class="n">label</span><span class="o">=</span><span class="n">label</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="n">start</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="n">stop</span><span class="p">)</span>
            <span class="k">if</span> <span class="n">get_vad</span><span class="p">:</span>
                <span class="n">label</span> <span class="o">=</span> <span class="n">lbl</span>
            <span class="n">features</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">feat</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
611

Anthony Larcher's avatar
Anthony Larcher committed
612
613
        <span class="n">features</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">hstack</span><span class="p">(</span><span class="n">features</span><span class="p">)</span>

Anthony Larcher's avatar
doc    
Anthony Larcher committed
614
615
616
        <span class="c1"># If the VAD is not required, return all labels at True</span>
        <span class="k">if</span> <span class="n">label</span> <span class="ow">is</span> <span class="kc">None</span><span class="p">:</span>
            <span class="n">label</span> <span class="o">=</span> <span class="n">numpy</span><span class="o">.</span><span class="n">ones</span><span class="p">(</span><span class="n">feat</span><span class="o">.</span><span class="n">shape</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">dtype</span><span class="o">=</span><span class="s1">&#39;bool&#39;</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
617

Anthony Larcher's avatar
doc    
Anthony Larcher committed
618
619
620
        <span class="c1"># Apply the final post-processing on the concatenated features</span>
        <span class="k">return</span> <span class="bp">self</span><span class="o">.</span><span class="n">post_processing</span><span class="p">(</span><span class="n">features</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span></div>

Anthony Larcher's avatar
Anthony Larcher committed
621
<div class="viewcode-block" id="FeaturesServer.mean_std"><a class="viewcode-back" href="../api/featuresserver.html#features_server.FeaturesServer.mean_std">[docs]</a>    <span class="k">def</span> <span class="nf">mean_std</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">show</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="mi">0</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
Anthony Larcher's avatar
Anthony Larcher committed
622
623
624
625
626
627
628
629
630
631
632
        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        Compute the mean and standard deviation vectors for a segment of acoustic features</span>

<span class="sd">        :param show: the ID of the show</span>
<span class="sd">        :param channel: the index of the channel</span>
<span class="sd">        :param start: index of the first frame of the selected segment</span>
<span class="sd">        :param stop: index of the last frame of the selected segment</span>

<span class="sd">        :return: the number of frames, the mean of the frames and their standard deviation</span>
<span class="sd">        &quot;&quot;&quot;</span>
        <span class="n">feat</span><span class="p">,</span> <span class="n">_</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">load</span><span class="p">(</span><span class="n">show</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="n">channel</span><span class="p">,</span> <span class="n">start</span><span class="o">=</span><span class="n">start</span><span class="p">,</span> <span class="n">stop</span><span class="o">=</span><span class="n">stop</span><span class="p">)</span>
Anthony Larcher's avatar
Anthony Larcher committed
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718