In [1]:
%pylab inline
from pyannote.core import notebook


Populating the interactive namespace from numpy and matplotlib

SlidingWindowFeature (pyannote.core.feature.SlidingWindowFeature)


In [2]:
from pyannote.core import SlidingWindowFeature, SlidingWindow

SlidingWindowFeature are used to manage feature vectors extracted on a sliding window (e.g. MFCC in audio processing).


In [3]:
# one 4-dimensional feature vector extracted every 100ms from a 200ms window
frame = SlidingWindow(start=0.0, step=0.100, duration=0.200)

# random for illustration purposes
data = np.random.randn(100, 4)

features = SlidingWindowFeature(data, frame)

Cropping

You may use crop to extract a temporal subset:


In [4]:
help(features.crop)


Help on method crop in module pyannote.core.feature:

crop(self, focus, mode=u'loose', fixed=None) method of pyannote.core.feature.SlidingWindowFeature instance
    Extract frames as numpy array
    
    Parameters
    ----------
    focus : Segment or Timeline
    mode : {'loose', 'strict', 'center', 'fixed'}, optional
        In 'strict' mode, only frames fully included in focus coverage are
        returned. In 'loose' mode, any intersecting frames are returned. In
        'center' mode, first and last frames are chosen to be the positions
        whose centers are the closest to the focus start and end times.
        Defaults to 'loose'.
    fixed : float, optional
        When provided and mode is 'center', override focus duration to make
        sure two `focus` with the same duration always result in the same
        (fixed) number of frames being selected.
    
    Returns
    -------
    data : numpy array
        (nSamples, nFeatures) numpy array
    
    See also
    --------
    SlidingWindow.crop


In [5]:
from pyannote.core import Segment
features.crop(Segment(2, 3))


Out[5]:
array([[-0.170939  ,  0.7268368 , -1.11357192,  0.9102115 ],
       [ 0.75526988,  0.13631738, -1.12959046,  0.57945519],
       [-1.63332126, -1.05239927, -2.80404685, -3.19025518],
       [-1.2622323 ,  0.80263563,  0.8912935 ,  0.85251067],
       [-0.58865284, -1.05005899,  0.5468816 ,  1.03976293],
       [ 2.99740924,  1.544513  , -2.18700361, -0.19051365],
       [-1.16020413,  2.75010658, -1.63448261,  0.96354481],
       [-1.09404058, -0.56915077, -0.73265453, -0.5412315 ],
       [-3.83225883,  2.48916336, -0.475149  , -0.56418448],
       [ 0.01583975, -1.41733235, -0.47454703, -1.18346613],
       [ 0.4350982 , -0.61821957,  0.0458578 , -0.66109202],
       [ 1.39603516,  1.00657646,  1.67931705,  0.01362444],
       [ 0.95027176, -0.02961472, -0.71587331, -0.04884979]])

Need help?

You can always try the following...
Who knows? It might give you the information you are looking for!


In [6]:
help(SlidingWindowFeature)


Help on class SlidingWindowFeature in module pyannote.core.feature:

class SlidingWindowFeature(__builtin__.object)
 |  Periodic feature vectors
 |  
 |  Parameters
 |  ----------
 |  data : (nSamples, nFeatures) numpy array
 |  
 |  sliding_window : SlidingWindow
 |  
 |  Methods defined here:
 |  
 |  __getitem__(self, i)
 |      Get ith feature vector
 |  
 |  __init__(self, data, sliding_window)
 |  
 |  crop(self, focus, mode=u'loose', fixed=None)
 |      Extract frames as numpy array
 |      
 |      Parameters
 |      ----------
 |      focus : Segment or Timeline
 |      mode : {'loose', 'strict', 'center', 'fixed'}, optional
 |          In 'strict' mode, only frames fully included in focus coverage are
 |          returned. In 'loose' mode, any intersecting frames are returned. In
 |          'center' mode, first and last frames are chosen to be the positions
 |          whose centers are the closest to the focus start and end times.
 |          Defaults to 'loose'.
 |      fixed : float, optional
 |          When provided and mode is 'center', override focus duration to make
 |          sure two `focus` with the same duration always result in the same
 |          (fixed) number of frames being selected.
 |      
 |      Returns
 |      -------
 |      data : numpy array
 |          (nSamples, nFeatures) numpy array
 |      
 |      See also
 |      --------
 |      SlidingWindow.crop
 |  
 |  getDimension(self)
 |      Dimension of feature vectors
 |  
 |  getExtent(self)
 |  
 |  getNumber(self)
 |      Number of feature vectors
 |  
 |  iterfeatures(self, window=False)
 |      Feature vector iterator
 |      
 |      Parameters
 |      ----------
 |      window : bool, optional
 |          When True, yield both feature vector and corresponding window.
 |          Default is to only yield feature vector
 |  
 |  ----------------------------------------------------------------------
 |  Data descriptors defined here:
 |  
 |  __dict__
 |      dictionary for instance variables (if defined)
 |  
 |  __weakref__
 |      list of weak references to the object (if defined)