Features

Load the 'cssigps' Python modules and the get_dropbox_path module.


In [58]:
import os
import sys

import matplotlib.pyplot as plt
import numpy as np

def add_project_module_path():
    """
    Simple method for adding our module to the sys path
    """
    path_items=(os.getcwd()).split(os.sep)
    path_items.pop()
    final_path=""
    for item in path_items:
        final_path+=item+os.sep
    sys.path.append(final_path+'cssigps')
    sys.path.append(final_path)

# method for adding module to sys path
add_project_module_path()
from cssigps.dataset import *
from cssigps.feature import *
from get_dropbox_path import *
%matplotlib inline


path=get_dropbox_path()+"yes-no-test"

# return a list of the audio test samples
samples = find_testsamples(path)
print('\nFound '+str(len(samples))+' samples')
sample_set = SampleSet(samples)
sample_set.stats()

def plot_matrix(matrix,vmin=None,vmax=None):
    """plot matrix for visualization"""
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
    ax.set_aspect('equal')
    if vmin and vmax:
        plt.imshow(matrix, interpolation='nearest', cmap=plt.cm.gist_heat, vmin=vmin, vmax=vmax)
    else:
        plt.imshow(matrix, interpolation='nearest', cmap=plt.cm.gist_heat)
    plt.colorbar()
    plt.show()


def column_normalization(f):
    nfeat = f #np.zeros(f.shape, dtype=f.dtype)
    transposed = nfeat.T.copy()
    rows,cols = transposed.shape
    print('dtype: '+str(f.dtype))
    print('rows: '+str(rows))
    print('cols: '+str(cols))
    for row in range(rows):
        transposed[row,:]=(transposed[row,:]) * (1./float(transposed[row,:].sum()))
    return transposed.T

factory=FBankFeature()
examples = sample_set.class_rep()
col=0
for e in examples:
    feat = factory.generate(e)
    feat2 = column_normalization(feat.reshape(99,26).T)
    print('\t'+str(e))
    print('\tfeat.shape: '+str(feat.shape))
    print('\tfeat: '+str(feat))
    plot_matrix(feat.reshape(99,26).T)
    plot_matrix(feat2,0.,0.06)


Found 63 samples
Num samples: 63
Num classes: 3
	'Y' : 14
	'NONE' : 32
	'N' : 14
dtype: float64
rows: 99
cols: 26
	<sample name='sample_YNQ_0010_0_NONE.wav' y='NONE' >
	feat.shape: (2574,)
	feat: [ 4.2429842   7.50860337  4.71642199 ...,  8.57873837  8.26381446
  8.54466684]
dtype: float64
rows: 99
cols: 26
	<sample name='sample_YNQ_0010_11_Y.wav' y='Y' >
	feat.shape: (2574,)
	feat: [ 3.70363257  7.89002065  6.06892711 ...,  7.58632253  7.84268419
  8.04019244]
dtype: float64
rows: 99
cols: 26
	<sample name='sample_YNQ_0010_31_N.wav' y='N' >
	feat.shape: (2574,)
	feat: [ 5.4634016   7.2719628   5.5918219  ...,  9.21638551  8.7711766   8.5163071 ]

In [37]:


In [ ]: