Mercurial > hg > hybrid-music-recommender-using-content-based-and-social-information
comparison Code/genre_classification/classification/preprocess_spectrograms_7digital.py @ 24:68a62ca32441
Organized python scripts
author | Paulo Chiliguano <p.e.chiilguano@se14.qmul.ac.uk> |
---|---|
date | Sat, 15 Aug 2015 19:16:17 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
23:45e6f85d0ba4 | 24:68a62ca32441 |
---|---|
1 # -*- coding: utf-8 -*- | |
2 """ | |
3 Created on Thu Jul 23 21:55:58 2015 | |
4 | |
5 @author: paulochiliguano | |
6 """ | |
7 | |
8 | |
9 import tables | |
10 import numpy as np | |
11 import cPickle | |
12 import sklearn.preprocessing as preprocessing | |
13 | |
14 #Read HDF5 file that contains log-mel spectrograms | |
15 filename = '/homes/pchilguano/msc_project/dataset/7digital/features/\ | |
16 feats.h5' | |
17 with tables.openFile(filename, 'r') as f: | |
18 features = f.root.x.read() | |
19 #filenames = f.root.filenames.read() | |
20 | |
21 #Pre-processing of spectrograms mean=0 and std=1 | |
22 n_per_example = np.prod(features.shape[1:-1]) | |
23 number_of_features = features.shape[-1] | |
24 flat_data = features.view() | |
25 flat_data.shape = (-1, number_of_features) | |
26 scaler = preprocessing.StandardScaler().fit(flat_data) | |
27 flat_data = scaler.transform(flat_data) | |
28 flat_data.shape = (features.shape[0], -1) | |
29 | |
30 f = file('/homes/pchilguano/msc_project/dataset/7digital/features/\ | |
31 feats.pkl', 'wb') | |
32 cPickle.dump(flat_data, f, protocol=cPickle.HIGHEST_PROTOCOL) | |
33 f.close() |