Beispiel #1
0
import math, shutil
from spectral import get_mfcc
from util_func import parse_arguments, parse_classes

typeFeature = "MFCC"
name_cur_file = os.path.basename(__file__)
name_cur_dir = os.path.dirname(os.path.abspath(__file__))
source_dir = os.getcwd()

##### Parse Arguments #####
arg_elements = [sys.argv[i] for i in range(1, len(sys.argv))]
arguments = parse_arguments(arg_elements)
name_var = arguments['data_type']
target_path = arguments['rep_test']
param_str = arguments['param']
classes = parse_classes(arguments['classes'])
N_classes = len(classes)
param_list = parse_classes(param_str)
window_step=float(param_list[0] )# in seconds, hop size between two successive mfcc windows
window_size=float(param_list[1] )# in seconds, size of MFCC window
highfreq=float(param_list[2]) # maximal analysis frequency for mfcc
lowfreq=float(param_list[3]) # minimal analysis frequency for mfcc
size=int(param_list[4]) # number of mfcc coef
N=int(param_list[5]) #contextual window
slide=int(param_list[6])
threshold = int(param_list[7])
compute_delta = param_list[8]

##### Initialize label dic #####
label_dic = {}
for i in range(len(classes)):
import os as os
import scikits.audiolab as audlab
import cPickle, gzip, sys
import numpy as np
import math, shutil
from spectral import get_mfcc
from util_func import parse_arguments, parse_classes

arg_elements = [sys.argv[i] for i in range(1, len(sys.argv))]
arguments = parse_arguments(arg_elements)
name_var = arguments['data_type']
classes = parse_classes(arguments['classes'])
# name_var = 'test'
window_step = float(arguments['window_step'])
window_size = float(arguments['window_size'])
highfreq = int(arguments['highfreq'])
lowfreq = int(arguments['lowfreq'])
size = int(arguments['size'])
N = int(arguments['N'])
slide = int(arguments['slide'])
exp_path = arguments['exp_path']
threshold = int(arguments['threshold'])
compute_delta = arguments['deltas']
shutil.copyfile('/home/piero/Documents/Scripts/format_pickle_data3.py', os.path.join(exp_path,'format_pickle_data3.py'))
N_classes = len(classes)
label_dic = {}
for k in range(N_classes):
    label_dic[classes[k]] = k
initial_path = '/home/piero/Documents/Speech_databases/DeGIV/29-30-Jan/'+name_var+'_labels' # label files
target_path = os.path.join(exp_path,'data')
os.chdir(initial_path)
Beispiel #3
0
log('number of test batches:' + str(n_test))
for j in range(n_test):
    output = rnn.predict(test[j], mask_test[j])
    for jj in range(output.shape[1]):
        for kk in range(output.shape[0]):
            p = output[kk, jj, :]
            l = label_test[j][kk, jj, :]
            p_sorted = (-p).argsort()
            l_sorted = (-l).argsort()
            if any(l):
                n_data += 1
                if p_sorted[0] == l_sorted[0]:
                    correct_number += 1
                confusion_matrix[p_sorted[0], l_sorted[0]] += 1
                class_occurrence[l_sorted[0]] += 1

# ############################## TEST RESULTS #############################
confusion_matrix = 100 * confusion_matrix / class_occurrence
error_rate = 100 * (1.0 - correct_number / n_data)
log('Error rate is ' + str(error_rate) + ' (%)')
log('Confusion Matrix is \n\n ' + str(confusion_matrix) + ' (%)\n')
rnn.save(filesave)
N = len(confusion_matrix) # number of classes =pred_mat.shape[1] ?
class_list = parse_classes(classes)
Docpath = fileTex
TabPath = fileTex
Docname = "Confusion_matrix"
TabName = "table"
texfile = DocTabTex(np.around(confusion_matrix, 2), class_list,"Tab01","legende",Docpath,TabPath,Docname,TabName,option='t',commentaire="%test commentaires")
texfile.creatTex();
Beispiel #4
0
import os as os
import scikits.audiolab as audlab
import cPickle, gzip, sys
import numpy as np
import math, shutil
from spectral import get_mfcc
from util_func import parse_arguments, parse_classes

arg_elements = [sys.argv[i] for i in range(1, len(sys.argv))]
arguments = parse_arguments(arg_elements)
name_var = arguments['data_type']
classes = parse_classes(arguments['classes'])
# name_var = 'test'
window_step = float(arguments['window_step'])
window_size = float(arguments['window_size'])
highfreq = int(arguments['highfreq'])
lowfreq = int(arguments['lowfreq'])
size = int(arguments['size'])
N = int(arguments['N'])
slide = int(arguments['slide'])
exp_path = arguments['exp_path']
threshold = int(arguments['threshold'])
compute_delta = arguments['deltas']
shutil.copyfile('/home/piero/Documents/Scripts/format_pickle_data.py',
                os.path.join(exp_path, 'format_pickle_data.py'))
N_classes = len(classes)
label_dic = {}
for k in range(N_classes):
    label_dic[classes[k]] = k
initial_path = '/home/piero/Documents/Speech_databases/DeGIV/29-30-Jan/'\
                        +name_var+'_labels' # label files
import os as os
import scikits.audiolab as audlab
import cPickle, gzip, sys
import numpy as np
import shutil
from spectral import get_mfcc
from util_func import parse_arguments, parse_classes

arg_elements = [sys.argv[i] for i in range(1, len(sys.argv))]
arguments = parse_arguments(arg_elements)
name_var = arguments['data_type']
classes = parse_classes(arguments['classes'])
constraints = parse_classes(arguments['constraints'])
# name_var = 'test'
window_step = float(arguments['window_step'])
window_size = float(arguments['window_size'])
highfreq = int(arguments['highfreq'])
lowfreq = int(arguments['lowfreq'])
size = int(arguments['size'])
N = int(arguments['N'])
slide = int(arguments['slide'])
exp_path = arguments['exp_path']
threshold = int(arguments['threshold'])

shutil.copyfile('/home/piero/Documents/Scripts/format_pickle_data.py',
                os.path.join(exp_path,'format_pickle_data.py'))
N_classes = len(classes)
label_dic = {}
for k in range(N_classes):
    label_dic[classes[k]] = k
initial_path = '/home/piero/Documents/Speech_databases/DeGIV/29-30-Jan/'+name_var+'_labels' # label files
Beispiel #6
0
import math, shutil
from spectral import get_mfcc, MFSC
from util_func import parse_arguments, parse_classes

name_cur_file = os.path.basename(__file__)
name_cur_dir = os.path.dirname(os.path.abspath(__file__))
source_dir = os.getcwd()

##### Parse Arguments #####
arg_elements = [sys.argv[i] for i in range(1, len(sys.argv))]
arguments = parse_arguments(arg_elements)
network_type = arguments['net']
name_var = arguments['data_type']
target_path = arguments['rep_test']
param_str = arguments['param']
classes_1 = parse_classes(arguments['classes_1'])
classes_2 = parse_classes(arguments['classes_2'])
param_list = parse_classes(param_str)
window_step = float(
    param_list[0])  # in seconds, hop size between two successive mfcc windows
window_size = float(param_list[1])  # in seconds, size of MFCC window
highfreq = float(param_list[2])  # maximal analysis frequency for mfcc
lowfreq = float(param_list[3])  # minimal analysis frequency for mfcc
size = int(param_list[4])  # number of mfcc coef
N = int(param_list[5])  #contextual window
slide = int(param_list[6])
threshold = int(param_list[7])
compute_delta = param_list[8]
if network_type == "DNN":
    typeFeature = "MFCC"
elif network_type == "CNN":
Beispiel #7
0
import time
import matplotlib.pyplot as plt
from util_func import parse_classes, parse_arguments

typeFeature = "MFCC"
name_cur_file = os.path.basename(__file__)
name_cur_dir = os.path.dirname(os.path.abspath(__file__))
source_dir = os.getcwd()

##### Parse Arguments #####
arg_elements = [sys.argv[i] for i in range(1, len(sys.argv))]
arguments = parse_arguments(arg_elements)
name_var = arguments['data_type']
target_path = arguments['rep_test']
param_str = arguments['param']
classes = parse_classes(arguments['classes'])
N_classes = len(classes)
param_list = parse_classes(param_str)
window_step = float(
    param_list[0])  # in seconds, hop size between two successive mfcc windows
window_size = float(param_list[1])  # in seconds, size of MFCC window
highfreq = float(param_list[2])  # maximal analysis frequency for mfcc
lowfreq = float(param_list[3])  # minimal analysis frequency for mfcc
size = int(param_list[4])  # number of mfcc coef
occurrence_threshold = int(param_list[5])
compute_delta = param_list[6]
max_seq_length = int(arguments['max_seq_len'])
n_stream = int(arguments['n_stream'])
max_batch_len = int(arguments['max_batch_len'])

##### Initialize label dic #####
# Data formatting for full multi-label

import os as os
import scikits.audiolab as audlab
import cPickle, gzip, sys
import numpy as np
import math, shutil
from spectral import get_mfcc
from util_func import parse_arguments, parse_classes

arg_elements = [sys.argv[i] for i in range(1, len(sys.argv))]
arguments = parse_arguments(arg_elements)
name_var = arguments["data_type"]
classes_1 = parse_classes(arguments["classes_1"])
classes_2 = parse_classes(arguments["classes_2"])
window_step = float(arguments["window_step"])
window_size = float(arguments["window_size"])
highfreq = int(arguments["highfreq"])
lowfreq = int(arguments["lowfreq"])
size = int(arguments["size"])
N = int(arguments["N"])
slide = int(arguments["slide"])
exp_path = arguments["exp_path"]
threshold = int(arguments["threshold"])
compute_delta = arguments["deltas"]
shutil.copyfile(
    "/home/piero/Documents/Scripts/format_data_full_multi_label.py",
    os.path.join(exp_path, "format_data_full_multi_label.py"),
)
N_classes_1 = len(classes_1)
N_classes_2 = len(classes_2)
import os as os
import scikits.audiolab as audlab
import cPickle, gzip, sys
import numpy as np
import math, shutil
from spectral import get_mfcc
from util_func import parse_arguments, parse_classes

arg_elements = [sys.argv[i] for i in range(1, len(sys.argv))]
arguments = parse_arguments(arg_elements)
name_var = arguments["data_type"]
classes = parse_classes(arguments["classes"])
# name_var = 'test'
window_step = float(arguments["window_step"])
window_size = float(arguments["window_size"])
highfreq = int(arguments["highfreq"])
lowfreq = int(arguments["lowfreq"])
size = int(arguments["size"])
N = int(arguments["N"])
slide = int(arguments["slide"])
exp_path = arguments["exp_path"]
threshold = int(arguments["threshold"])
compute_delta = arguments["deltas"]
shutil.copyfile(
    "/home/piero/Documents/Scripts/format_pickle_data2.py", os.path.join(exp_path, "format_pickle_data2.py")
)
N_classes = len(classes)
label_dic = {}
for k in range(N_classes):
    label_dic[classes[k]] = k
initial_path = "/home/piero/Documents/Speech_databases/DeGIV/29-30-Jan/" + name_var + "_labels"  # label files
Beispiel #10
0
if filename == 'None':
    filename = None
initParams = arguments['initparams']
if initParams == 'None':
    initParams = None
filesave = arguments['filesave']
fileTex = arguments['fileTex']
n_epoch = int(arguments['epoch'])
lrate = np.float32(arguments['lambda'])
train_data_spec = arguments['train_data']
valid_data_spec = arguments['valid_data']
test_data_spec = arguments['test_data']
multi_label = arguments['multi_label']
multi_env = arguments['multi_env']
if multi_label == "true" or multi_env == "true":
    classes_1 = parse_classes(arguments['classes_1'])
    classes_2 = parse_classes(arguments['classes_2'])
else:
    classes = parse_classes(arguments['classes'])
input, label, mask = read(train_data_spec)
test, label_test, mask_test = read(test_data_spec)
valid, label_valid, mask_valid = read(valid_data_spec)
n_streams = np.shape(label)[1]
len_batch = np.shape(label)[2]
n_classes = np.shape(label)[3]
n_batches = len(input)
n_test = len(test)
n_valid = len(valid)
error = np.zeros((n_test, n_streams, len_batch, n_classes))

# ############################ Create instance of class RNN #########################
import math, shutil
from spectral import get_mfcc
from util_func import parse_arguments, parse_classes

typeFeature = "MFCC"
name_cur_file = os.path.basename(__file__)
name_cur_dir = os.path.dirname(os.path.abspath(__file__))
source_dir = os.getcwd()

##### Parse Arguments #####
arg_elements = [sys.argv[i] for i in range(1, len(sys.argv))]
arguments = parse_arguments(arg_elements)
name_var = arguments['data_type']
target_path = arguments['rep_test']
param_str = arguments['param']
classes_1 = parse_classes(arguments['classes_1'])
classes_2 = parse_classes(arguments['classes_2'])
param_list = parse_classes(param_str)
window_step=float(param_list[0] )# in seconds, hop size between two successive mfcc windows
window_size=float(param_list[1] )# in seconds, size of MFCC window
highfreq=float(param_list[2]) # maximal analysis frequency for mfcc
lowfreq=float(param_list[3]) # minimal analysis frequency for mfcc
size=int(param_list[4]) # number of mfcc coef
N=int(param_list[5]) #contextual window
slide=int(param_list[6])
threshold = int(param_list[7])
compute_delta = param_list[8]

##### Initialize label dic #####
N_classes_1 = len(classes_1)
N_classes_2 = len(classes_2)
import time
import matplotlib.pyplot as plt
from util_func import parse_classes, parse_arguments

typeFeature = "MFCC"
name_cur_file = os.path.basename(__file__)
name_cur_dir = os.path.dirname(os.path.abspath(__file__))
source_dir = os.getcwd()

##### Parse Arguments #####
arg_elements = [sys.argv[i] for i in range(1, len(sys.argv))]
arguments = parse_arguments(arg_elements)
name_var = arguments["data_type"]
target_path = arguments["rep_test"]
param_str = arguments["param"]
classes = parse_classes(arguments["classes"])
N_classes = len(classes)
param_list = parse_classes(param_str)
window_step = float(param_list[0])  # in seconds, hop size between two successive mfcc windows
window_size = float(param_list[1])  # in seconds, size of MFCC window
highfreq = float(param_list[2])  # maximal analysis frequency for mfcc
lowfreq = float(param_list[3])  # minimal analysis frequency for mfcc
size = int(param_list[4])  # number of mfcc coef
occurrence_threshold = int(param_list[5])
compute_delta = param_list[6]
max_seq_length = int(arguments["max_seq_len"])
n_stream = int(arguments["n_stream"])
max_batch_len = int(arguments["max_batch_len"])

##### Initialize label dic #####
label_dic = {}
Beispiel #13
0
print 'Confusion Matrix is \n\n ' + str(np.around(confusion_matrix, 2)) + ' (%)\n'
if '+' in class_str:
    mult = class_str.split('+')
    class_list =[]
    for j in range(len(mult[0].split(','))):
        if j==0:
            string_1 = mult[0].split(',')[j][2:]
        elif j ==(len(mult[0].split(',')) - 1):
            string_1 = mult[0].split(',')[j][:-1]
        else:
            string_1 = mult[0].split(',')[j]
        for k in range(len(mult[1].split(','))):
            if k==0:
                class_list.append( string_1 + '_'  + mult[1].split(',')[k][1:])
            elif k==(len(mult[1].split(',')) - 1):
                class_list.append(string_1 + '_ '+ mult[1].split(',')[k][:-2])
            else:
                class_list.append(string_1 + '_' + mult[1].split(',')[k])
else:
    class_list = utils.parse_classes(class_str)
for i in range(len(class_list)):
    if '_' in class_list[i]:
        class_list[i] = class_list[i].replace('_', ' ')
print(class_list)
Docpath = filepath
TabPath = filepath
Docname = nametex
TabName = "table"
texfile = DocTabTex(np.around(confusion_matrix, 2), class_list,"Tab01","legende",Docpath,TabPath,Docname,TabName,option='t',commentaire="%test ommanataire")
texfile.creatTex();