Commit 08b64efb authored by Anthony Larcher's avatar Anthony Larcher
Browse files

code refactoring

parent 6bb3e8e4
......@@ -28,18 +28,19 @@ Copyright 2014-2016 Anthony Larcher and Sylvain Meignier
useful parameters for speaker verification.
"""
from ctypes import *
from ctypes.util import find_library
import logging
import numpy
import os
import sys
from ctypes import *
from ctypes.util import find_library
PARALLEL_MODULE = 'multiprocessing' # can be , threading, multiprocessing MPI is planned in the future
PARAM_TYPE = numpy.float32
STAT_TYPE = numpy.float64
THEANO_CONFIG = "gpu" # can be gpu or cpu
# Import bosaris-like classes
from sidekit.bosaris import IdMap
from sidekit.bosaris import Ndx
......@@ -141,8 +142,6 @@ if libsvm_loaded:
from sidekit.svm_scoring import *
from sidekit.svm_training import *
__author__ = "Anthony Larcher and Sylvain Meignier"
__copyright__ = "Copyright 2014-2016 Anthony Larcher and Sylvain Meignier"
__license__ = "LGPL"
......@@ -150,6 +149,7 @@ __maintainer__ = "Anthony Larcher"
__email__ = "anthony.larcher@univ-lemans.fr"
__status__ = "Production"
__docformat__ = 'reStructuredText'
__version__="1.1.6"
# __all__ = ["io",
# "vad",
......
......@@ -404,9 +404,8 @@
<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>
<span class="n">mode</span><span class="o">=</span><span class="s">&#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>
<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>
<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="n">mode</span><span class="o">=</span><span class="s">&#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>
<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>
<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>
<span class="k">if</span> <span class="n">label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
......@@ -439,12 +438,12 @@
<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>
<span class="n">mode</span><span class="o">=</span><span class="s">&#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><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">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>
<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>
<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>
<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>
<span class="k">if</span> <span class="n">label</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
<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>
......@@ -541,8 +540,6 @@
<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>
<span class="c">#logging.debug(&quot;*** show: &quot;+show)</span>
<span class="c"># Get the selected segment</span>
<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="s">&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="n">__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>
<span class="c"># Deal with the case where start &lt; 0 or stop &gt; feat.shape[0]</span>
......@@ -556,7 +553,7 @@
<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>
<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="bp">None</span> <span class="ow">or</span> <span class="n">stop</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">)</span>
<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="bp">None</span> <span class="ow">or</span> <span class="n">stop</span> <span class="ow">is</span> <span class="bp">None</span><span class="p">)</span>
<span class="c"># Get the data between start and stop</span>
<span class="c"># Concatenate all required datasets</span>
......@@ -590,7 +587,7 @@
<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="s">&#39;bool&#39;</span><span class="p">)</span>
<span class="c"># 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="s">&#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="s">&#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="s">&#39;edge&#39;</span><span class="p">)</span>
<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>
......
......@@ -498,6 +498,7 @@
<span class="k">if</span> <span class="n">framerate</span> <span class="o">&gt;</span> <span class="n">read_framerate</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="s">&quot;Warning in read_audio, up-sampling function is not implemented yet!&quot;</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">read_framerate</span> <span class="o">%</span> <span class="nb">float</span><span class="p">(</span><span class="n">framerate</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">framerate</span> <span class="o">==</span> <span class="n">read_framerate</span><span class="p">:</span>
<span class="k">print</span><span class="p">(</span><span class="s">&quot;downsample&quot;</span><span class="p">)</span>
<span class="n">sig</span> <span class="o">=</span> <span class="n">decimate</span><span class="p">(</span><span class="n">sig</span><span class="p">,</span> <span class="nb">int</span><span class="p">(</span><span class="n">read_framerate</span> <span class="o">/</span> <span class="nb">float</span><span class="p">(</span><span class="n">framerate</span><span class="p">)),</span> <span class="n">n</span><span class="o">=</span><span class="bp">None</span><span class="p">,</span> <span class="n">ftype</span><span class="o">=</span><span class="s">&#39;iir&#39;</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="mi">0</span><span class="p">)</span>
<span class="k">return</span> <span class="n">sig</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">numpy</span><span class="o">.</span><span class="n">float32</span><span class="p">),</span> <span class="n">framerate</span>
......
......@@ -289,6 +289,7 @@
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">with</span> <span class="n">h5py</span><span class="o">.</span><span class="n">File</span><span class="p">(</span><span class="n">input_filename</span><span class="p">,</span> <span class="s">&quot;r&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
<span class="k">return</span> <span class="n">f</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="n">key</span><span class="p">)</span><span class="o">.</span><span class="n">value</span>
</div>
<div class="viewcode-block" id="read_dict_hdf5"><a class="viewcode-back" href="../sidekit_io.html#sidekit_io.read_dict_hdf5">[docs]</a><span class="k">def</span> <span class="nf">read_dict_hdf5</span><span class="p">(</span><span class="n">input_filename</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;</span>
......@@ -501,8 +502,8 @@
<span class="n">fh</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">FileHandler</span><span class="p">(</span><span class="n">filename</span><span class="p">)</span>
<span class="n">fh</span><span class="o">.</span><span class="n">setFormatter</span><span class="p">(</span><span class="n">logging</span><span class="o">.</span><span class="n">Formatter</span><span class="p">(</span><span class="n">frm</span><span class="p">))</span>
<span class="n">fh</span><span class="o">.</span><span class="n">setLevel</span><span class="p">(</span><span class="n">level</span><span class="p">)</span>
<span class="n">root</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">fh</span><span class="p">)</span>
</pre></div></div>
<span class="n">root</span><span class="o">.</span><span class="n">addHandler</span><span class="p">(</span><span class="n">fh</span><span class="p">)</span></div>
</pre></div>
</div>
</div>
......
This diff is collapsed.
......@@ -86,7 +86,7 @@
<div class="body" role="main">
<div class="section" id="featuresserver">
<h1>FeaturesServer<a class="headerlink" href="#featuresserver" title="Permalink to this headline"></a></h1>
<span id="id1"></span><h1>FeaturesServer<a class="headerlink" href="#featuresserver" title="Permalink to this headline"></a></h1>
<dl class="class">
<dt id="features_server.FeaturesServer">
<em class="property">class </em><code class="descclassname">features_server.</code><code class="descname">FeaturesServer</code><span class="sig-paren">(</span><em>features_extractor=None</em>, <em>feature_filename_structure=None</em>, <em>sources=None</em>, <em>dataset_list=None</em>, <em>mask=None</em>, <em>feat_norm=None</em>, <em>global_cmvn=None</em>, <em>dct_pca=False</em>, <em>dct_pca_config=None</em>, <em>sdc=False</em>, <em>sdc_config=None</em>, <em>delta=None</em>, <em>double_delta=None</em>, <em>delta_filter=None</em>, <em>context=None</em>, <em>traps_dct_nb=None</em>, <em>rasta=None</em>, <em>keep_all_features=True</em><span class="sig-paren">)</span><a class="reference internal" href="_modules/features_server.html#FeaturesServer"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#features_server.FeaturesServer" title="Permalink to this definition"></a></dt>
......
......@@ -97,7 +97,7 @@
</dt>
<dt><a href="statserver.html#statserver.StatServer.adapt_mean_MAP">adapt_mean_MAP() (statserver.StatServer method)</a>
<dt><a href="statserver.html#statserver.StatServer.adapt_mean_map">adapt_mean_map() (statserver.StatServer method)</a>
</dt>
......@@ -236,12 +236,12 @@
<dt><a href="statserver.html#statserver.StatServer.estimate_hidden">estimate_hidden() (statserver.StatServer method)</a>
</dt>
</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="statserver.html#statserver.StatServer.estimate_map">estimate_map() (statserver.StatServer method)</a>
</dt>
</dl></td>
<td style="width: 33%" valign="top"><dl>
<dt><a href="statserver.html#statserver.StatServer.estimate_spectral_norm_stat1">estimate_spectral_norm_stat1() (statserver.StatServer method)</a>
</dt>
......@@ -258,10 +258,6 @@
<dt><a href="featuresextractor.html#features_extractor.FeaturesExtractor.extract">extract() (features_extractor.FeaturesExtractor method)</a>
</dt>
<dt><a href="statserver.html#statserver.StatServer.extract_ivector_uncertainty">extract_ivector_uncertainty() (statserver.StatServer method)</a>
</dt>
</dl></td>
</tr></table>
......@@ -343,6 +339,10 @@
<table style="width: 100%" class="indextable genindextable"><tr>
<td style="width: 33%" valign="top"><dl>
<dt><a href="statserver.html#statserver.StatServer.generator">generator() (statserver.StatServer method)</a>
</dt>
<dt><a href="statserver.html#statserver.StatServer.get_between_covariance_stat1">get_between_covariance_stat1() (statserver.StatServer method)</a>
</dt>
......
......@@ -107,7 +107,7 @@
Kong Aik Lee &amp;
Sylvain Meignier</td>
</tr>
<tr class="field-even field"><th class="field-name">Version:</th><td class="field-body">1.1.0 of 2016/07/05</td>
<tr class="field-even field"><th class="field-name">Version:</th><td class="field-body">1.6.0 of 2016/10/31</td>
</tr>
</tbody>
</table>
......
This diff is collapsed.
......@@ -26,7 +26,7 @@
<link rel="top" title="SIDEKIT 1.1.6 documentation" href="../index.html" />
<link rel="up" title="Enter the SIDEKIT" href="shorttuto.html" />
<link rel="next" title="1. Save the features in HDF5 format" href="hdf5.html" />
<link rel="prev" title="How to manage the data: IdMap, Ndx, Scores and Keys" href="dataManagment.html" />
<link rel="prev" title="How to manage the data: IdMap, Ndx, Key, Scores and StatServer" href="dataManagment.html" />
</head>
<body role="document">
<div class="related" role="navigation" aria-label="related navigation">
......@@ -42,7 +42,7 @@
<a href="hdf5.html" title="1. Save the features in HDF5 format"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="dataManagment.html" title="How to manage the data: IdMap, Ndx, Scores and Keys"
<a href="dataManagment.html" title="How to manage the data: IdMap, Ndx, Key, Scores and StatServer"
accesskey="P">previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">SIDEKIT 1.1.6 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../howto.html" >How to</a> &raquo;</li>
......@@ -53,7 +53,7 @@
<div class="sphinxsidebarwrapper">
<h4>Previous topic</h4>
<p class="topless"><a href="dataManagment.html"
title="previous chapter">How to manage the data: IdMap, Ndx, Scores and Keys</a></p>
title="previous chapter">How to manage the data: IdMap, Ndx, Key, Scores and StatServer</a></p>
<h4>Next topic</h4>
<p class="topless"><a href="hdf5.html"
title="next chapter">1. Save the features in HDF5 format</a></p>
......@@ -141,7 +141,7 @@ acoustic features. The HDF5 format is the prefered serialization format in <stro
<a href="hdf5.html" title="1. Save the features in HDF5 format"
>next</a> |</li>
<li class="right" >
<a href="dataManagment.html" title="How to manage the data: IdMap, Ndx, Scores and Keys"
<a href="dataManagment.html" title="How to manage the data: IdMap, Ndx, Key, Scores and StatServer"
>previous</a> |</li>
<li class="nav-item nav-item-0"><a href="../index.html">SIDEKIT 1.1.6 documentation</a> &raquo;</li>
<li class="nav-item nav-item-1"><a href="../howto.html" >How to</a> &raquo;</li>
......
......@@ -20,7 +20,7 @@ Welcome to SIDEKIT’s documentation!
Kong Aik Lee \&
Sylvain Meignier
:Version: 1.1.0 of 2016/07/05
:Version: 1.6.0 of 2016/10/31
Implementation
--------------
......
......@@ -74,7 +74,8 @@ class FeaturesExtractor(object):
"""
:param audio_filename_structure: a string that gives the structure of the input file to process
:param feature_filename_structure: a string that gives the structure of the output file to write
:param sampling_frequency: optional, only required if processing RAW PCM. For other formats, this information is read from the file
:param sampling_frequency: optional, only required if processing RAW PCM. For other formats, this information
is read from the file
:param lower_frequency: lower frequency (in Herz) of the filter bank
:param higher_frequency: higher frequency of the filter bank
:param filter_bank: type of fiter scale to use, can be "lin" or "log" (for linear of log-scale)
......@@ -82,14 +83,16 @@ class FeaturesExtractor(object):
:param window_size: size of the sliding window to process (in seconds)
:param shift: time shift of the sliding window (in seconds)
:param ceps_number: number of cepstral coefficients to extract
:param vad: type of voice actovoty detection algorithm to use. Can be "energy", "snr", "percentil" or "lbl" to read from a file
:param vad: type of voice actovoty detection algorithm to use. Can be "energy", "snr", "percentil" or "lbl"
to read from a file
:param snr: signal to noise ratio used for "snr" vad algorithm
:param pre_emphasis: value given for the pre-emphasis filter (default is 0.97)
:param save_param: list of strings that indicate which parameters to save. The strings can be:
"cep" for cepstral coefficients, "fb" for filter-banks, "energy" for the log-energy, "bnf"
for bottle-neck features and "vad" for the frame selection labels. In the resulting files, parameters are
always concatenated in the following order: (energy,fb, cep, bnf, vad_label). Default keeps all.
:param keep_all_features: boolean, if True, all frames are writen; if False, keep only frames according to the vad label
:param keep_all_features: boolean, if True, all frames are writen; if False, keep only frames according to
the vad label
"""
# Set the default values
......@@ -173,9 +176,12 @@ class FeaturesExtractor(object):
:param show: ID if the show
:param channel: channel number (0 if mono file)
:param input_audio_filename: name of the input audio file to consider if the name of the audio file is independent from the ID of the show
:param output_feature_filename: name of the output feature file to consider if the name of the feature file is independent from the ID of the show
:param backing_store: boolean, if False, nothing is writen to disk, if True, the file is writen to disk when closed
:param input_audio_filename: name of the input audio file to consider if the name of the audio file is
independent from the ID of the show
:param output_feature_filename: name of the output feature file to consider if the name of the feature file
is independent from the ID of the show
:param backing_store: boolean, if False, nothing is writen to disk, if True, the file is writen to disk
when closed
:return: an hdf5 file handler
"""
......@@ -373,8 +379,6 @@ class FeaturesExtractor(object):
fb, fb_mean, fb_std,
bnf, bnf_mean, bnf_std,
label)
h5f.close()
def save_multispeakers(self,
......@@ -402,26 +406,24 @@ class FeaturesExtractor(object):
tmp_dict = dict()
nb = 0
for show, id, start, stop in zip(idmap.rightids, idmap.leftids, idmap.start, idmap.stop):
for show, _id, start, stop in zip(idmap.rightids, idmap.leftids, idmap.start, idmap.stop):
if skip_existing_file:
if keep_all:
file_name = output_feature_filename.format(show)
else:
file_name = output_feature_filename.format(show+'/'+id)
file_name = output_feature_filename.format(show+'/' + _id)
if os.path.isfile(file_name):
logging.info('existing file: SKIP '+file_name)
continue
#else:
# logging.info('existing file: KEEP '+file_name)
if show not in tmp_dict:
tmp_dict[show] = dict()
if id not in tmp_dict[show]:
tmp_dict[show][id] = numpy.arange(start, stop-1)
if _id not in tmp_dict[show]:
tmp_dict[show][_id] = numpy.arange(start, stop-1)
nb += 1
else:
tmp_dict[show][id] = numpy.concatenate((tmp_dict[show][id], numpy.arange(start, stop-1)), axis=0)
tmp_dict[show][_id] = numpy.concatenate((tmp_dict[show][_id], numpy.arange(start, stop-1)), axis=0)
output_show = list()
output_id = list()
......@@ -439,21 +441,22 @@ class FeaturesExtractor(object):
h5f.close()
self.vad = param_vad
l = energy.shape[0]
for id in tmp_dict[show]:
idx = tmp_dict[show][id]
for _id in tmp_dict[show]:
idx = tmp_dict[show][_id]
idx = idx[idx < l]
_, threshold_id = self._vad(None, energy[idx], None, None)
logging.info('show: ' + show + ' cluster: ' + id + ' thr:' + str(threshold_id))
logging.info('show: ' + show + ' cluster: ' + _id + ' thr:' + str(threshold_id))
label_id = energy > threshold_id
label[idx] = label_id[idx]
if not keep_all:
output_show.append(show+'/'+id)
output_id.append(id)
output_show.append(show + '/' + _id)
output_id.append(_id)
output_start.append(0)
output_stop.append(idx.shape[0])
logging.info('keep_all id: '+show+ ' show: '+show+'/'+id+' start: 0 stop: '+str(idx.shape[0]))
self._save(show+'/'+id,
logging.info('keep_all id: ' + show + ' show: ' + show + '/' + _id + ' start: 0 stop: ' +
str(idx.shape[0]))
self._save(show+'/' + _id,
output_feature_filename,
save_param, cep[idx],
energy[idx],
......
......@@ -338,9 +338,8 @@ class FeaturesServer(object):
numpy.pad(feat,
((max(self.context[0] - start, 0), max(stop - feat.shape[0] + self.context[1] + 1, 0)),
(0, 0)),
mode='edge')[start - self.context[0] + max(self.context[0] - start, 0)
:stop + self.context[1] + max(self.context[0] - start, 0), :],
win_size=1+sum(self.context)
mode='edge')[start - self.context[0] + max(self.context[0] - start, 0):
stop + self.context[1] + max(self.context[0] - start, 0), :], win_size=1+sum(self.context)
).reshape(-1, (1+sum(self.context)) * feat.shape[1])
if label is not None:
......@@ -373,12 +372,12 @@ class FeaturesServer(object):
feat,
((self.context[0]-start, stop - feat.shape[0] + self.context[1] + 1), (0, 0)),
mode='edge'
)[start-self.context[0]
+ max(self.context[0]-start, 0):stop + self.context[1] + max(self.context[0]-start, 0),:],
)[start-self.context[0] +
max(self.context[0]-start, 0):stop + self.context[1] + max(self.context[0]-start, 0), :],
win_size=1+sum(self.context)
).transpose(0, 2, 1)
hamming_dct = (dct_basis(self.traps_dct_nb, sum(self.context) + 1)
* numpy.hamming(sum(self.context) + 1)).T
hamming_dct = (dct_basis(self.traps_dct_nb, sum(self.context) + 1) *
numpy.hamming(sum(self.context) + 1)).T
if label is not None:
context_label = label[start:stop]
......@@ -475,8 +474,6 @@ class FeaturesServer(object):
else:
h5f = self.features_extractor.extract(show, channel, input_audio_filename=input_feature_filename)
#logging.debug("*** show: "+show)
# Get the selected segment
dataset_length = h5f[show + "/" + next(h5f[show].__iter__())].shape[0]
# Deal with the case where start < 0 or stop > feat.shape[0]
......@@ -490,7 +487,7 @@ class FeaturesServer(object):
pad_end = stop - dataset_length if stop > dataset_length else 0
stop = min(stop, dataset_length)
global_cmvn = self.global_cmvn and not (start is None or stop is None)
global_cmvn = self.global_cmvn and not (start is None or stop is None)
# Get the data between start and stop
# Concatenate all required datasets
......@@ -524,7 +521,7 @@ class FeaturesServer(object):
label = numpy.ones(feat.shape[0], dtype='bool')
# Pad the segment if needed
feat = numpy.pad(feat, ((pad_begining, pad_end), (0, 0)), mode='edge')
label = numpy.pad(label, ((pad_begining, pad_end)), mode='edge')
label = numpy.pad(label, (pad_begining, pad_end), mode='edge')
stop += pad_begining + pad_end
h5f.close()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment