p@24: # -*- coding: utf-8 -*- p@24: """ p@24: Created on Thu Jul 23 21:55:58 2015 p@24: p@24: @author: paulochiliguano p@24: """ p@24: p@24: p@24: import tables p@24: import numpy as np p@24: import cPickle p@24: import sklearn.preprocessing as preprocessing p@24: p@24: #Read HDF5 file that contains log-mel spectrograms p@24: filename = '/homes/pchilguano/msc_project/dataset/7digital/features/\ p@24: feats.h5' p@24: with tables.openFile(filename, 'r') as f: p@24: features = f.root.x.read() p@24: #filenames = f.root.filenames.read() p@24: p@24: #Pre-processing of spectrograms mean=0 and std=1 p@24: n_per_example = np.prod(features.shape[1:-1]) p@24: number_of_features = features.shape[-1] p@24: flat_data = features.view() p@24: flat_data.shape = (-1, number_of_features) p@24: scaler = preprocessing.StandardScaler().fit(flat_data) p@24: flat_data = scaler.transform(flat_data) p@24: flat_data.shape = (features.shape[0], -1) p@24: p@24: f = file('/homes/pchilguano/msc_project/dataset/7digital/features/\ p@24: feats.pkl', 'wb') p@24: cPickle.dump(flat_data, f, protocol=cPickle.HIGHEST_PROTOCOL) p@24: f.close()