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)
In [37]:
In [ ]: