annotate Code/genre_classification/classification/preprocess_spectrograms_7digital.py @ 47:b0186d4a4496 tip

Move 7Digital dataset to Downloads
author Paulo Chiliguano <p.e.chiliguano@se14.qmul.ac.uk>
date Sat, 09 Jul 2022 00:50:43 -0500
parents 68a62ca32441
children
rev   line source
p@24 1 # -*- coding: utf-8 -*-
p@24 2 """
p@24 3 Created on Thu Jul 23 21:55:58 2015
p@24 4
p@24 5 @author: paulochiliguano
p@24 6 """
p@24 7
p@24 8
p@24 9 import tables
p@24 10 import numpy as np
p@24 11 import cPickle
p@24 12 import sklearn.preprocessing as preprocessing
p@24 13
p@24 14 #Read HDF5 file that contains log-mel spectrograms
p@24 15 filename = '/homes/pchilguano/msc_project/dataset/7digital/features/\
p@24 16 feats.h5'
p@24 17 with tables.openFile(filename, 'r') as f:
p@24 18 features = f.root.x.read()
p@24 19 #filenames = f.root.filenames.read()
p@24 20
p@24 21 #Pre-processing of spectrograms mean=0 and std=1
p@24 22 n_per_example = np.prod(features.shape[1:-1])
p@24 23 number_of_features = features.shape[-1]
p@24 24 flat_data = features.view()
p@24 25 flat_data.shape = (-1, number_of_features)
p@24 26 scaler = preprocessing.StandardScaler().fit(flat_data)
p@24 27 flat_data = scaler.transform(flat_data)
p@24 28 flat_data.shape = (features.shape[0], -1)
p@24 29
p@24 30 f = file('/homes/pchilguano/msc_project/dataset/7digital/features/\
p@24 31 feats.pkl', 'wb')
p@24 32 cPickle.dump(flat_data, f, protocol=cPickle.HIGHEST_PROTOCOL)
p@24 33 f.close()