In [6]:
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()+"new-vowels-test"#+"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,envs=["Q1"])
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 matrix_expansion(matrix,n):
"""
duplicate rows of features to create a better MEL visualization.
The final size will rows * n x cols
"""
rows,cols= matrix.shape
nmatrix = np.zeros((rows*n,cols), dtype=f.dtype)
for row in range(rows):
for i in range(n):
nmatrix[(row*n)+i]=matrix[row]
return nmatrix
factory=FBankFeature()
examples = sample_set.class_rep()
col=0
for e in examples:
feat = factory.generate(e)
print('\t'+str(e))
print('\tfeat.shape: '+str(feat.shape))
print('\tfeat: '+str(feat))
plot_matrix(feat.reshape(99,26).T,-2.,17.5)
#plot_matrix(feat.reshape(99,26))
In [4]: