Esempio n. 1
0
print("F1 score %.2f"%f)
file_=open('run1.txt','a')
str1="act3={}, input_neurons={}, batchsize={}, loss={}, nb_filter={}, filter_length={}, optimizer={}".format(act3, input_neurons, batchsize, loss,nb_filter, filter_length, optimizer)
str2="EER={0:.2f} Precision={1:.2f} Recall={2:.2f} F1 score={3:.2f}".format(eer,p,r,f)
file_.write(str1+'\n'+str2+'\n')
file_.close()
"""
#file_logger.close()

miz = aud_model.Functional_Model(input_neurons=input_neurons,
                                 dropout=dropout,
                                 num_classes=num_classes,
                                 model=model,
                                 dimx=dimx,
                                 dimy=dimy,
                                 nb_filter=nb_filter,
                                 act1=act1,
                                 act2=act2,
                                 act3=act3,
                                 filter_length=filter_length,
                                 pool_size=pool_size,
                                 optimizer=optimizer,
                                 loss=loss)
#fit the model
#tr_y=to_categorical(tr_y,len(cfg.labels))
#v_y=to_categorical(v_y,len(cfg.labels))
#fold_='saved_models_3'
#if os.path.exists(fold_):
#    os.rmdir(fold_)
#os.mkdir(fold_)
#filepath=fold_+"/weights-improvement1-{epoch:02d}-{val_acc:.2f}.hdf5"
#checkpoint = ModelCheckpoint(filepath, monitor='val_acc', verbose=1, save_best_only=True, mode='max')
Esempio n. 2
0
    #aud_utils.check_dimension(feature[i],dimy[i],'defaults.yaml')

#tr_X=aud_utils.equalise(tr_X)

for i in range(len(feature)):
    tr_X[i]=aud_utils.mat_3d_to_nd(model,tr_X[i])
    print(tr_X[i].shape)
dimx=tr_X[0].shape[-2]

if prep=='dev':
    cross_validation=True
else:
    cross_validation=False
    
miz=aud_model.Functional_Model(input_neurons=input_neurons,cross_validation=cross_validation,dropout1=dropout1,
    act1=act1,act2=act2,act3=act3,nb_filter = nb_filter, filter_length=filter_length,
    num_classes=num_classes,
    model=model,dimx=dimx,dimy=dimy)

np.random.seed(68)
if cross_validation:
    kf = KFold(len(tr_X[0]),folds,shuffle=True,random_state=42)
    results=[]    
    for train_indices, test_indices in kf:
        train_x = list(np.zeros(len(feature),dtype='int'))
        test_x  = list(np.zeros(len(feature),dtype='int'))
        for i in range(len(feature)):
            train_x[i] = [tr_X[i][ii] for ii in train_indices]
            test_x[i]  = [tr_X[i][ii] for ii in test_indices]
            train_x[i] = np.array(train_x[i])
            test_x[i]  = np.array(test_x[i])
        train_y = [tr_y[ii] for ii in train_indices]
Esempio n. 3
0
print(tr_y.shape)

dimx = tr_X.shape[-2]
dimy = tr_X.shape[-1]
tr_X = aud_utils.mat_3d_to_nd(model, tr_X)
print(tr_X.shape)

if prep == 'dev':
    cross_validation = True
else:
    cross_validation = False

miz = aud_model.Functional_Model(input_neurons=input_neurons,
                                 dropout=0.2,
                                 num_classes=num_classes,
                                 model=model,
                                 dimx=dimx,
                                 dimy=dimy,
                                 loss=loss,
                                 optimizer=optimizer)

np.random.seed(68)
if cross_validation:
    kf = KFold(len(tr_X), folds, shuffle=True, random_state=42)
    results = []
    for train_indices, test_indices in kf:
        train_x = [tr_X[ii] for ii in train_indices]
        train_y = [tr_y[ii] for ii in train_indices]
        test_x = [tr_X[ii] for ii in test_indices]
        test_y = [tr_y[ii] for ii in test_indices]
        train_y = to_categorical(train_y, num_classes=len(labels))
        test_y = to_categorical(test_y, num_classes=len(labels))
Esempio n. 4
0
print(tr_X.shape)
print(tr_y.shape)

tr_X = aud_utils.mat_3d_to_nd(model, tr_X)
print(tr_X.shape)
dimx = tr_X.shape[-2]
dimy = tr_X.shape[-1]

if prep == 'dev':
    print "Number of folds", folds
    cross_validation = True
else:
    cross_validation = False

miz = aud_model.Functional_Model(num_classes=num_classes,
                                 model=model,
                                 dimx=dimx,
                                 dimy=dimy)

np.random.seed(68)
if cross_validation:
    kf = KFold(len(tr_X), folds, shuffle=True, random_state=42)
    results = []
    for train_indices, test_indices in kf:
        train_x = [tr_X[ii] for ii in train_indices]
        train_y = [tr_y[ii] for ii in train_indices]
        test_x = [tr_X[ii] for ii in test_indices]
        test_y = [tr_y[ii] for ii in test_indices]
        #train_y = to_categorical(train_y,num_classes=len(labels))
        #test_y = to_categorical(test_y,num_classes=len(labels))

        train_x = np.array(train_x)
Esempio n. 5
0
print(tr_X.shape)
dimx = tr_X.shape[-2]
dimy = tr_X.shape[-1]

if prep == 'dev':
    print "Number of folds", folds
    cross_validation = True
else:
    cross_validation = False
rnn_units = [20, 20]
miz = aud_model.Functional_Model(num_classes=num_classes,
                                 model=model,
                                 dimx=dimx,
                                 dimy=dimy,
                                 dropout=dropout1,
                                 filter_lenght=filter_length,
                                 act1=act1,
                                 act2=act2,
                                 nb_filter=nb_filter,
                                 rnn_units=rnn_units,
                                 act3=act3)

np.random.seed(68)
if cross_validation:
    kf = KFold(len(tr_X), folds, shuffle=True, random_state=42)
    results = []
    for train_indices, test_indices in kf:
        train_x = [tr_X[ii] for ii in train_indices]
        train_y = [tr_y[ii] for ii in train_indices]
        test_x = [tr_X[ii] for ii in test_indices]
        test_y = [tr_y[ii] for ii in test_indices]
Esempio n. 6
0
    aud_audio.extract(feature,
                      cfg.wav_eva_fd,
                      cfg.eva_fd + '/' + feature,
                      'parameters.yaml',
                      dataset=dataset)

############# LOAD DATA ###########################
tr_X, tr_y = seth.get_train_data()
dimx = tr_X.shape[-2]
dimy = tr_X.shape[-1]
tr_X = aud_utils.mat_3d_to_nd(model, tr_X)
miz = aud_model.Functional_Model(input_neurons=input_neurons,
                                 dropout=dropout,
                                 num_classes=num_classes,
                                 model=model,
                                 dimx=dimx,
                                 nb_filter=nb_filter,
                                 pool_size=pool_size,
                                 dimy=dimy,
                                 loss=loss,
                                 optimizer=optimizer)

if prep == 'dev':
    kf = KFold(len(tr_X), folds, shuffle=True, random_state=42)
    results = []
    for train_indices, test_indices in kf:
        train_x = [tr_X[ii] for ii in train_indices]
        train_y = [tr_y[ii] for ii in train_indices]
        test_x = [tr_X[ii] for ii in test_indices]
        test_y = [tr_y[ii] for ii in test_indices]
        train_y = to_categorical(train_y, num_classes=len(cfg.labels))
        test_y = to_categorical(test_y, num_classes=len(cfg.labels))
Esempio n. 7
0
tr_X = aud_utils.mat_3d_to_nd(model, tr_X)
print(tr_X.shape)
dimx = tr_X.shape[-2]
dimy = tr_X.shape[-1]

if prep == 'dev':
    print "Number of folds", folds
    cross_validation = True
else:
    cross_validation = False

## In case of Functional CRNN
miz = aud_model.Functional_Model(model=model,
                                 dimx=dimx,
                                 dimy=dimy,
                                 num_classes=num_classes,
                                 act1=act1,
                                 act2=act2,
                                 act3=act3)

np.random.seed(68)
if cross_validation:
    kf = KFold(len(tr_X), folds, shuffle=True, random_state=42)
    results = []
    for train_indices, test_indices in kf:
        train_x = [tr_X[ii] for ii in train_indices]
        train_y = [tr_y[ii] for ii in train_indices]
        test_x = [tr_X[ii] for ii in test_indices]
        test_y = [tr_y[ii] for ii in test_indices]

        train_x = np.array(train_x)
Esempio n. 8
0
                      cfg.wav_eva_fd,
                      cfg.eva_fd + '/' + feature,
                      'parameters.yaml',
                      dataset=dataset)

############# LOAD DATA ###########################
tr_X, tr_y = seth.get_train_data()
dimx = tr_X.shape[-2]
dimy = tr_X.shape[-1]
tr_X = aud_utils.mat_3d_to_nd(model, tr_X)
miz = aud_model.Functional_Model(input_neurons=input_neurons,
                                 dropout=dropout,
                                 num_classes=num_classes,
                                 model=model,
                                 dimx=dimx,
                                 nb_filter=nb_filter,
                                 act1=act1,
                                 act2=act2,
                                 act3=act3,
                                 filter_length=filter_length,
                                 dimy=dimy)

if prep == 'dev':
    kf = KFold(len(tr_X), folds, shuffle=True, random_state=42)
    results = []
    for train_indices, test_indices in kf:
        train_x = [tr_X[ii] for ii in train_indices]
        train_y = [tr_y[ii] for ii in train_indices]
        test_x = [tr_X[ii] for ii in test_indices]
        test_y = [tr_y[ii] for ii in test_indices]
        train_y = to_categorical(train_y, num_classes=len(cfg.labels))
Esempio n. 9
0
print(tr_X.shape)
print(tr_y.shape)    
    
tr_X=aud_utils.mat_3d_to_nd(model,tr_X)
print(tr_X.shape)
dimx=tr_X.shape[-2]
dimy=tr_X.shape[-1]

if prep=='dev':
    print "Number of folds",folds
    cross_validation=True
else:
    cross_validation=False

nb_filter     = [50    , 100]    
miz=aud_model.Functional_Model(model=model,dimx=dimx,dimy=dimy,num_classes=num_classes,act1=act1,act2=act2,act3=act3,nb_filter = nb_filter,dropout=dropout1)

np.random.seed(68)
if cross_validation:
    kf = KFold(len(tr_X),folds,shuffle=True,random_state=42)
    results=[]    
    for train_indices, test_indices in kf:
        train_x = [tr_X[ii] for ii in train_indices]
        train_y = [tr_y[ii] for ii in train_indices]
        test_x  = [tr_X[ii] for ii in test_indices]
        test_y  = [tr_y[ii] for ii in test_indices]
        #train_y = to_categorical(train_y,num_classes=len(labels))
        #test_y = to_categorical(test_y,num_classes=len(labels)) 
        
        train_x=np.array(train_x)
        train_y=np.array(train_y)