コード例 #1
0
def GetScalerSegData( fe_fd, agg_num, hop, fold, scaler ):
    with open( cfg.dev_cv_csv_path, 'rb') as f:
        reader = csv.reader(f)
        lis = list(reader)
        
    tr_Xlist, tr_ylist = [], []
    te_Xlist, te_ylist = [], []
        
    # read one line
    for li in lis:
        na = li[1]
        curr_fold = int(li[2])
        
        # get features, tags
        fe_path = fe_fd + '/' + na + '.f'
        info_path = cfg.dev_wav_fd + '/' + na + '.csv'
        tags = GetTags( info_path )
        y = TagsToCategory( tags )
        X = cPickle.load( open( fe_path, 'rb' ) )
        if scaler is not None:
            X = scaler.transform( X )
        
        # aggregate data
        X3d = mat_2d_to_3d( X, agg_num, hop )
        
        
        if curr_fold==fold:
            te_Xlist.append( X3d )
            te_ylist += [ y ]
        else:
            tr_Xlist.append( X3d )
            tr_ylist += [ y ]

    return np.array( tr_Xlist ), np.array( tr_ylist ), \
           np.array( te_Xlist ), np.array( te_ylist )
コード例 #2
0
def GetAllData_noMVN( fe_fd, agg_num, hop, fold,fea_dim):
		with open( cfg.dev_cv_csv_path, 'rb') as f:
				reader = csv.reader(f)
				lis = list(reader)
				
		tr_Xlist, tr_ylist = [], []
		te_Xlist, te_ylist = [], []
				
		# read one line
		for li in lis:
				na = li[1]
				curr_fold = int(li[2])
				
				# get features, tags
				fe_path = fe_fd + '/' + na + '.f'
				info_path = cfg.dev_wav_fd + '/' + na + '.csv'
				tags = GetTags( info_path )
				#print info_path
				y = TagsToCategory( tags )
				X = cPickle.load( open( fe_path, 'rb' ) )
				# aggregate data
				#print X_l.shape #(nframe=125,ndim=257)
				X3d = mat_2d_to_3d( X, agg_num, hop )
				X3d= reshapeX(X3d,fea_dim, agg_num) 
				
				if curr_fold==fold:
						te_Xlist.append( X3d )
						te_ylist += [ y ] * len( X3d )
				else:
						tr_Xlist.append( X3d )
						tr_ylist += [ y ] * len( X3d )

		return np.concatenate( tr_Xlist, axis=0 ), np.array( tr_ylist ),\
					 np.concatenate( te_Xlist, axis=0 ), np.array( te_ylist )
コード例 #3
0
def GetAllData_NAT(fe_fd, agg_num, hop, fold, scaler, fea_dim):
    with open(cfg.dev_cv_csv_path, 'rb') as f:
        reader = csv.reader(f)
        lis = list(reader)

    tr_Xlist, tr_ylist = [], []
    te_Xlist, te_ylist = [], []

    # read one line
    line_n = 0
    for li in lis:
        na = li[1]
        line_n = line_n + 1
        curr_fold = int(li[2])

        # get features, tags
        fe_path = fe_fd + '/' + na + '.f'
        info_path = cfg.dev_wav_fd + '/' + na + '.csv'
        tags = GetTags(info_path)
        #print info_path
        y = TagsToCategory(tags)
        X = cPickle.load(open(fe_path, 'rb'))
        #print X.shape
        X = scaler.transform(X)
        #print X.shape
        X_1 = X[:6, :]
        #print X_1.shape
        X_n = np.mean(X_1, axis=0)
        #print X_n.shape
        # aggregate data
        #print X_l.shape #(nframe=125,ndim=257)
        X3d = mat_2d_to_3d(X, agg_num, hop)
        X3d = reshapeX(X3d, fea_dim, agg_num)
        #print X3d.shape
        X_n = np.tile(X_n, (len(X3d), 1))
        #print X_n.shape
        X_in = np.concatenate((X3d, X_n), axis=1)
        #print X_in.shape # (nsampelPERutt=10,contextfr=33,ndim=257)
        #sys.exit()
        # reshape 3d to 4d
        #X4d_l = reshape_3d_to_4d( X3d_l)
        #X4d_r = reshape_3d_to_4d( X3d_r)
        #X4d_m = reshape_3d_to_4d( X3d_m)
        #X4d_d = reshape_3d_to_4d( X3d_d)
        # concatenate
        #X4d=mat_concate_multiinmaps4in(X3d_l, X3d_r, X3d_m, X3d_d)
        #print X4d.shape
        #sys.exit()

        if curr_fold == fold:
            te_Xlist.append(X_in)
            te_ylist += [y] * len(X_in)
        else:
            tr_Xlist.append(X_in)
            tr_ylist += [y] * len(X_in)
    print line_n
    return np.concatenate( tr_Xlist, axis=0 ), np.array( tr_ylist ),\
           np.concatenate( te_Xlist, axis=0 ), np.array( te_ylist )
コード例 #4
0
def recognize():

    with open(cfg.dev_cv_csv_path, 'rb') as f:
        reader = csv.reader(f)
        lis = list(reader)
        nl = 0
        # read one line
        for li in lis:
            na = li[1]
            curr_fold = int(li[2])

            nl = nl + 1
            #if fold==curr_fold:
            if 1 == 1:
                fe_path = fe_fd + '/' + na + '.f'
                print na
                print nl
                X = cPickle.load(open(fe_path, 'rb'))

                X = scaler.transform(X)

                X3d = mat_2d_to_3d(X, agg_num, hop)
                print X3d.shape
                X3d = reshapeX(X3d)

                if debug:
                    pred = dae.predict(X3d)

                get_3rd_layer_output = K.function(
                    [dae.layers[0].input,
                     K.learning_phase()], [dae.layers[3].output])
                layer_output = get_3rd_layer_output([X3d, 0])[0]
                print layer_output.shape
                # for the asymetric
                #out_path = 'your_dir/DCASE2016_task4_scrap_1ch_mfcc/Fe/htk_asyDAE' + '/' + na + '.f' #### change na[0:4]
                # for the symetric
                out_path = 'your_dir/DCASE2016_task4_scrap_1ch_mfcc/Fe/htk_syDAE' + '/' + na + '.f'  #### change na[0:4]
                if not debug:
                    cPickle.dump(layer_output,
                                 open(out_path, 'wb'),
                                 protocol=cPickle.HIGHEST_PROTOCOL)
                    print 'write done!'
                #sys.exit()
                if debug:
                    print layer_output.shape
                    #layer_output1=layer_output[5,:]
                    imgplot = plt.matshow(layer_output[:, :].T,
                                          origin='lower',
                                          aspect='auto')
                    plt.ylabel('Feature dims')
                    plt.xlabel('Frames')
                    title('Learned new feature: Nonnegative representations')
                    plt.colorbar()
                    plt.show()
                    #sys.pause()
                if debug:
                    #if nl==1:
                    fig = plt.figure()
                    ax = fig.add_subplot(2, 1, 1)
                    nfr = 3
                    ax.matshow(pred.T, origin='lower', aspect='auto')
                    #ax.matshow(pred[:,nfr*fea_dim:(nfr+1)*fea_dim].T, origin='lower', aspect='auto')
                    plt.ylabel('Frequency bins')
                    plt.xlabel('Frames')
                    #title('Reconstructed Fbank features')
                    ax = fig.add_subplot(2, 1, 2)
                    ax.matshow(X3d[:, nfr * fea_dim:(nfr + 1) * fea_dim].T,
                               origin='lower',
                               aspect='auto')
                    plt.ylabel('Frequency bins')
                    plt.xlabel('Frames')
                    #title('Original Fbank features')
                    plt.show()
                    pause
def recognize():

    with open(cfg.dev_cv_csv_path, 'rb') as f:
        reader = csv.reader(f)
        lis = list(reader)
        nl = 0
        # read one line
        for li in lis:
            na = li[1]
            curr_fold = int(li[2])

            nl = nl + 1
            #if fold==curr_fold:
            if 1 == 1:
                fe_path = fe_fd + '/' + na + '.f'
                print na
                print nl
                X = cPickle.load(open(fe_path, 'rb'))

                #X = scaler.transform( X )
                #print X.shape
                X3d = mat_2d_to_3d(X, agg_num, hop)
                #print X3d.shape
                X3d = reshapeX(X3d)
                #print X3d.shape

                if debug:
                    pred = dae.predict(X3d)
                    pred = reshapeX3(pred)
                    print pred.shape

                get_3rd_layer_output = K.function(
                    [dae.layers[0].input,
                     K.learning_phase()], [dae.layers[6].output])
                layer_output = get_3rd_layer_output([X3d, 0])[0]
                layer_output = reshapeX4(layer_output)
                print layer_output.shape

                out_path = '/vol/vssp/msos/yx/chime_home/DCASE2016_task4_scrap_2ch_wav_ipd_ild_overlap/Fe/convAE_m' + '/' + na + '.f'  #### change na[0:-4]
                if not debug:
                    cPickle.dump(layer_output,
                                 open(out_path, 'wb'),
                                 protocol=cPickle.HIGHEST_PROTOCOL)
                    print 'write done!'
                #sys.exit()
                if debug:
                    print layer_output.shape
                    #layer_output1=layer_output[5,:]
                    layer_output = reshapeX4(layer_output)
                    print layer_output.shape
                    imgplot = plt.matshow((layer_output[:, :]))
                    plt.colorbar()
                    plt.show()
                    #sys.pause()
                if debug:
                    #if nl==1:
                    #fig=plt.figure()
                    #ax=fig.add_subplot(2,1,1)
                    #nfr=3
                    #plt.plot(np.ravel(pred))
                    #wavio.write('out.wav',np.ravel(pred),16000,sampwidth=2)
                    wavio.write('out.wav',
                                reconstructWav(pred),
                                16000,
                                sampwidth=2)

                    print np.max(pred), np.min(pred)
                    #ax.matshow(pred[:,nfr*fea_dim:(nfr+1)*fea_dim].T, origin='lower', aspect='auto')
                    #ax=fig.add_subplot(2,1,2)
                    X3d = reshapeX3(X3d)
                    #plt.plot(np.ravel(X3d))
                    #wavio.write('in.wav',np.ravel(X3d),16000,sampwidth=2)
                    wavio.write('in.wav',
                                reconstructWav(X3d),
                                16000,
                                sampwidth=2)
                    print np.max(X3d), np.min(X3d)
                    #plt.show()
                    pause
                if debug:
                    w1 = dae.layers[1].get_weights()[0]
                    print w1.shape
                    b = w1[150, 0, 0, :]
                    print b.shape
                    #plt.axis('off')
                    #b=scipy.signal.firwin(40,0.5,window=('kaiser',8))
                    #print b
                    plt.subplot(2, 1, 1)
                    plt.plot(b, 'b')
                    plt.subplot(2, 1, 2)
                    w, h = freqz(b)
                    m = 20 * np.log10(np.divide(abs(h), max(abs(h))))
                    mi = np.argmin(m)
                    print mi
                    ma = np.argmax(m)
                    print ma
                    plt.plot(w, m, 'r')
                    plt.show()
                    pause
コード例 #6
0
def GetAllData_separate( fe_fd_right, fe_fd_left, fe_fd_mean, fe_fd_diff, fe_fd_ipd, fe_fd_ild, agg_num, hop, fold ):
    with open( cfg.dev_cv_csv_path, 'rb') as f:
        reader = csv.reader(f)
        lis = list(reader)
        
    tr_Xlist1, tr_Xlist2, tr_ylist = [], [], []
    te_Xlist1, te_Xlist2, te_ylist = [], [], []
        
    # read one line
    for li in lis:
        na = li[1]
        curr_fold = int(li[2])
        
        # get features, tags
        #fe_path_left = fe_fd_left + '/' + na + '.f'
        #fe_path_right = fe_fd_right + '/' + na + '.f'
        fe_path_mean = fe_fd_mean + '/' + na + '.f'
        #fe_path_diff = fe_fd_diff + '/' + na + '.f'
        #fe_path_ipd = fe_fd_ipd + '/' + na + '.f'
        fe_path_ild = fe_fd_ild + '/' + na + '.f'
        #fe_path_ori = fe_fd_ori + '/' + na + '.f'
        info_path = cfg.dev_wav_fd + '/' + na + '.csv'
        tags = GetTags( info_path )
        #print info_path
        y = TagsToCategory( tags )
        #X_l = cPickle.load( open( fe_path_left, 'rb' ) )
        #X_r = cPickle.load( open( fe_path_right, 'rb' ) )
        X_m = cPickle.load( open( fe_path_mean, 'rb' ) )
        #X_d = cPickle.load( open( fe_path_diff, 'rb' ) )
        #X_ipd = cPickle.load( open( fe_path_ipd, 'rb' ) )
        X_ild = cPickle.load( open( fe_path_ild, 'rb' ) )
        #X_o = cPickle.load( open( fe_path_ori, 'rb' ) )
        
        # aggregate data
        #print X_l.shape #(nframe=125,ndim=257)
        #X3d_l = mat_2d_to_3d( X_l, agg_num, hop )
        #print X3d_l.shape # (nsampelPERutt=10,contextfr=33,ndim=257)
        #X3d_r = mat_2d_to_3d( X_r, agg_num, hop )
        X3d_m = mat_2d_to_3d( X_m, agg_num, hop )
        #X3d_d = mat_2d_to_3d( X_d, agg_num, hop )
        #X3d_ipd = mat_2d_to_3d( X_ipd, agg_num, hop )
        X3d_ild = mat_2d_to_3d( X_ild, agg_num, hop )
        #X3d_o = mat_2d_to_3d( X_o, agg_num, hop )
        # reshape 3d to 4d
        #X4d_l = reshape_3d_to_4d( X3d_l)
        #X4d_r = reshape_3d_to_4d( X3d_r)
        #X4d_m = reshape_3d_to_4d( X3d_m)
        #X4d_d = reshape_3d_to_4d( X3d_d)
        # concatenate
        #X4d=mat_concate_multiinmaps6in(X3d_l, X3d_r, X3d_m, X3d_d, X3d_ipd, X3d_ild)
        #print X4d.shape      
        #sys.exit()       
        
        if curr_fold==fold:
            te_Xlist1.append( X3d_m )
            te_Xlist2.append( X3d_ild )
            te_ylist += [ y ] * len( X3d_m )
        else:
            tr_Xlist1.append( X3d_m )
            tr_Xlist2.append( X3d_ild )
            tr_ylist += [ y ] * len( X3d_m )

    return np.concatenate( tr_Xlist1, axis=0 ), np.concatenate( tr_Xlist2, axis=0 ), np.array( tr_ylist ),\
           np.concatenate( te_Xlist1, axis=0 ), np.concatenate( te_Xlist2, axis=0 ), np.array( te_ylist )
def recognize():
    ## prepare data
    #_, _, te_X, te_y = pp_data.GetAllData(fe_fd_right, fe_fd_left, fe_fd_mean, fe_fd_diff, agg_num, hop, fold )
    ##te_X = reshapeX(te_X)
    #print te_X.shape
    
    # do recognize and evaluation
    thres = 0.4     # thres, tune to prec=recall, if smaller, make prec smaller
    n_labels = len( cfg.labels )
    
    gt_roll = []
    pred_roll = []
    result_roll = []
    y_true_binary_c = []
    y_true_file_c = []
    y_true_binary_m = []
    y_true_file_m = []
    y_true_binary_f = []
    y_true_file_f = []
    y_true_binary_v = []
    y_true_file_v = []
    y_true_binary_p = []
    y_true_file_p = []
    y_true_binary_b = []
    y_true_file_b = []
    y_true_binary_o = []
    y_true_file_o = []
    with open( cfg.dev_cv_csv_path, 'rb') as f:
        reader = csv.reader(f)
        lis = list(reader)
    
        # read one line
        for li in lis:
            na = li[1]
            curr_fold = int(li[2])
            
            if fold==curr_fold:
                # get features, tags
                fe_path_left = fe_fd_left + '/' + na + '.f'
                fe_path_right = fe_fd_right + '/' + na + '.f'
                fe_path_mean = fe_fd_mean + '/' + na + '.f'
                fe_path_diff = fe_fd_diff + '/' + na + '.f'
                fe_path_ipd = fe_fd_ipd + '/' + na + '.f'
                fe_path_ild = fe_fd_ild + '/' + na + '.f'
                #fe_path_ori = fe_fd_ori + '/' + na + '.f'
                info_path = cfg.dev_wav_fd + '/' + na + '.csv'
                #print na
                tags = pp_data.GetTags( info_path )
                #print tags
                y = pp_data.TagsToCategory( tags )
                #print y
                #sys.exit()
                #X_l = cPickle.load( open( fe_path_left, 'rb' ) )
                #X_r = cPickle.load( open( fe_path_right, 'rb' ) )
                X_m = cPickle.load( open( fe_path_mean, 'rb' ) )
                #X_d = cPickle.load( open( fe_path_diff, 'rb' ) )
                #X_ipd = cPickle.load( open( fe_path_ipd, 'rb' ) )
                #X_ild = cPickle.load( open( fe_path_ild, 'rb' ) )
                #X_o = cPickle.load( open( fe_path_ori, 'rb' ) )

                # aggregate data
                #X3d_l = mat_2d_to_3d( X_l, agg_num, hop )
                #X3d_r = mat_2d_to_3d( X_r, agg_num, hop )
                X3d_m = mat_2d_to_3d( X_m, agg_num, hop )
   		#X3d_d = mat_2d_to_3d( X_d, agg_num, hop )
                #X3d_ipd = mat_2d_to_3d( X_ipd, agg_num, hop )
   		#X3d_ild = mat_2d_to_3d( X_ild, agg_num, hop )
   		#X3d_o = mat_2d_to_3d( X_o, agg_num, hop )
     	        ## reshape 3d to 4d
       	        #X4d_l = reshape_3d_to_4d( X3d_l)
                #X4d_r = reshape_3d_to_4d( X3d_r)
                #X4d_m = reshape_3d_to_4d( X3d_m)
                #X4d_d = reshape_3d_to_4d( X3d_d)
                # concatenate
                #X4d=mat_concate_multiinmaps6in(X3d_l, X3d_r, X3d_m, X3d_d, X3d_ipd, X3d_ild)
                X3d_m=reshapeX1(X3d_m)
                #X4d=np.swapaxes(X4d,1,2) # or np.transpose(x,(1,0,2))  1,0,2 is axis
                te_X1=X3d_m
                #te_X2=X3d_ild
                #te_X1 = reshapeX1(te_X1)
                #te_X2 = reshapeX2(te_X2)
                
                if debug:
                    # with a Sequential model
                    #md.summary()
                    print na
                    get_3rd_layer_output = K.function([md.layers[0].input, K.learning_phase()], [md.layers[4].output])
                    layer_output = get_3rd_layer_output([te_X1, 0])[0]
                    print layer_output.shape
                    #layer_output1=layer_output[5,:,:]
                    layer_output1=layer_output[:,16,:]
                    imgplot=plt.matshow((layer_output1.T))
                    #imgplot.set_cmap('spectral')
                    plt.colorbar()
                    plt.show()
                    sys.pause()
                
                #p_y_pred = md.predict( [te_X1,te_X2] )
                p_y_pred = md.predict( te_X1 )
                p_y_pred = np.mean( p_y_pred, axis=0 )     # shape:(n_label)
                pred = np.zeros(n_labels)
                pred[ np.where(p_y_pred>thres) ] = 1
                ind=0
                for la in cfg.labels:
                    if la=='S':
                        break
                    elif la=='c':
                        y_true_file_c.append(na)
                        y_true_binary_c.append(y[ind])
                    elif la=='m':
                        y_true_file_m.append(na)
                        y_true_binary_m.append(y[ind])
                    elif la=='f':
                        y_true_file_f.append(na)
                        y_true_binary_f.append(y[ind])
                    elif la=='v':
                        y_true_file_v.append(na)
                        y_true_binary_v.append(y[ind])
                    elif la=='p':
                        y_true_file_p.append(na)
                        y_true_binary_p.append(y[ind])
                    elif la=='b':
                        y_true_file_b.append(na)
                        y_true_binary_b.append(y[ind])
                    elif la=='o':
                        y_true_file_o.append(na)
                        y_true_binary_o.append(y[ind])
                    result=[na,la,p_y_pred[ind]]
                    result_roll.append(result)
                    ind=ind+1
                
                
                pred_roll.append( pred )
                gt_roll.append( y )
    
    pred_roll = np.array( pred_roll )
    gt_roll = np.array( gt_roll )
    #write csv for EER computation
    csvfile=file('result.csv','wb')
    writer=csv.writer(csvfile)
    #writer.writerow(['fn','label','score'])
    writer.writerows(result_roll)
    csvfile.close()
    
    # calculate prec, recall, fvalue
    prec, recall, fvalue = prec_recall_fvalue( pred_roll, gt_roll, thres )
    # EER for each tag : [ 'c', 'm', 'f', 'v', 'p', 'b', 'o', 'S' ]
    EER_c=eer.compute_eer('result.csv', 'c', dict(zip(y_true_file_c, y_true_binary_c)))
    EER_m=eer.compute_eer('result.csv', 'm', dict(zip(y_true_file_m, y_true_binary_m)))
    EER_f=eer.compute_eer('result.csv', 'f', dict(zip(y_true_file_f, y_true_binary_f)))
    EER_v=eer.compute_eer('result.csv', 'v', dict(zip(y_true_file_v, y_true_binary_v)))
    EER_p=eer.compute_eer('result.csv', 'p', dict(zip(y_true_file_p, y_true_binary_p)))
    EER_b=eer.compute_eer('result.csv', 'b', dict(zip(y_true_file_b, y_true_binary_b)))
    EER_o=eer.compute_eer('result.csv', 'o', dict(zip(y_true_file_o, y_true_binary_o)))
    EER=(EER_c+EER_m+EER_v+EER_p+EER_f+EER_b+EER_o)/7.0
    print prec, recall, fvalue
    print EER_c,EER_m,EER_f,EER_v,EER_p,EER_b,EER_o
    print EER
コード例 #8
0
def recognize():

    # do recognize and evaluation
    thres = 0.4  # thres, tune to prec=recall, if smaller, make prec smaller
    n_labels = len(cfg.labels)

    gt_roll = []
    pred_roll = []
    result_roll = []
    y_true_binary_c = []
    y_true_file_c = []
    y_true_binary_m = []
    y_true_file_m = []
    y_true_binary_f = []
    y_true_file_f = []
    y_true_binary_v = []
    y_true_file_v = []
    y_true_binary_p = []
    y_true_file_p = []
    y_true_binary_b = []
    y_true_file_b = []
    y_true_binary_o = []
    y_true_file_o = []
    pred_roll_c = []
    gt_roll_c = []
    pred_roll_m = []
    gt_roll_m = []
    pred_roll_f = []
    gt_roll_f = []
    pred_roll_v = []
    gt_roll_v = []
    pred_roll_p = []
    gt_roll_p = []
    pred_roll_b = []
    gt_roll_b = []
    pred_roll_o = []
    gt_roll_o = []
    with open(cfg.dev_cv_csv_path, 'rb') as f:
        reader = csv.reader(f)
        lis = list(reader)

        # read one line
        line_n = 0
        for li in lis:
            na = li[1]
            curr_fold = int(li[2])

            if fold == curr_fold:
                line_n = line_n + 1
                print line_n
                # get features, tags
                fe_path = fe_fd + '/' + na + '.f'
                info_path = cfg.dev_wav_fd + '/' + na + '.csv'
                #info_path = '/vol/vssp/msos/yx/chime_home/chunk_annotations/annotations' + '/' + na + '.csv'
                #print na
                tags = pp_data.GetTags(info_path)
                #print tags
                y = pp_data.TagsToCategory(tags)
                #print y
                #sys.exit()
                X = cPickle.load(open(fe_path, 'rb'))

                X = scaler.transform(X)
                X_1 = X[:6, :]
                X_n = np.mean(X_1, axis=0)

                # aggregate data
                X3d = mat_2d_to_3d(X, agg_num, hop)
                ## reshape 3d to 4d
                #X4d = reshape_3d_to_4d( X3d)
                #X4d=np.swapaxes(X4d,2,3) # or np.transpose(x,(1,0,2))  1,0,2 is axis
                #X4d=reshapeX( X)
                X3d = reshapeX(X3d)
                #print X3d.shape
                X_n = np.tile(X_n, (len(X3d), 1))
                X_in = np.concatenate((X3d, X_n), axis=1)

                p_y_pred = md.predict(X_in)
                p_y_pred = np.mean(p_y_pred, axis=0)  # shape:(n_label)
                pred = np.zeros(n_labels)
                pred[np.where(p_y_pred > thres)] = 1
                ind = 0
                for la in cfg.labels:
                    if la == 'S':
                        break
                    elif la == 'c':
                        y_true_file_c.append(na)
                        y_true_binary_c.append(y[ind])
                        pred_roll_c.append(pred[ind])
                        gt_roll_c.append(y[ind])
                    elif la == 'm':
                        y_true_file_m.append(na)
                        y_true_binary_m.append(y[ind])
                        pred_roll_m.append(pred[ind])
                        gt_roll_m.append(y[ind])
                    elif la == 'f':
                        y_true_file_f.append(na)
                        y_true_binary_f.append(y[ind])
                        pred_roll_f.append(pred[ind])
                        gt_roll_f.append(y[ind])
                    elif la == 'v':
                        y_true_file_v.append(na)
                        y_true_binary_v.append(y[ind])
                        pred_roll_v.append(pred[ind])
                        gt_roll_v.append(y[ind])
                    elif la == 'p':
                        y_true_file_p.append(na)
                        y_true_binary_p.append(y[ind])
                        pred_roll_p.append(pred[ind])
                        gt_roll_p.append(y[ind])
                    elif la == 'b':
                        y_true_file_b.append(na)
                        y_true_binary_b.append(y[ind])
                        pred_roll_b.append(pred[ind])
                        gt_roll_b.append(y[ind])
                    elif la == 'o':
                        y_true_file_o.append(na)
                        y_true_binary_o.append(y[ind])
                        pred_roll_o.append(pred[ind])
                        gt_roll_o.append(y[ind])
                    result = [na, la, p_y_pred[ind]]
                    result_roll.append(result)
                    ind = ind + 1

                pred_roll.append(pred)
                gt_roll.append(y)

    pred_roll = np.array(pred_roll)
    gt_roll = np.array(gt_roll)
    pred_roll_c = np.array(pred_roll_c)
    gt_roll_c = np.array(gt_roll_c)
    pred_roll_m = np.array(pred_roll_m)
    gt_roll_m = np.array(gt_roll_m)
    pred_roll_f = np.array(pred_roll_f)
    gt_roll_f = np.array(gt_roll_f)
    pred_roll_v = np.array(pred_roll_v)
    gt_roll_v = np.array(gt_roll_v)
    pred_roll_p = np.array(pred_roll_p)
    gt_roll_p = np.array(gt_roll_p)
    pred_roll_b = np.array(pred_roll_b)
    gt_roll_b = np.array(gt_roll_b)
    pred_roll_o = np.array(pred_roll_o)
    gt_roll_o = np.array(gt_roll_o)
    #write csv for EER computation
    csvfile = file('result.csv', 'wb')
    writer = csv.writer(csvfile)
    #writer.writerow(['fn','label','score'])
    writer.writerows(result_roll)
    csvfile.close()

    # calculate prec, recall, fvalue
    prec, recall, fvalue = prec_recall_fvalue(pred_roll, gt_roll, thres)
    prec_c, recall_c, fvalue_c = prec_recall_fvalue(pred_roll_c, gt_roll_c,
                                                    thres)
    prec_m, recall_m, fvalue_m = prec_recall_fvalue(pred_roll_m, gt_roll_m,
                                                    thres)
    prec_f, recall_f, fvalue_f = prec_recall_fvalue(pred_roll_f, gt_roll_f,
                                                    thres)
    prec_v, recall_v, fvalue_v = prec_recall_fvalue(pred_roll_v, gt_roll_v,
                                                    thres)
    prec_p, recall_p, fvalue_p = prec_recall_fvalue(pred_roll_p, gt_roll_p,
                                                    thres)
    prec_b, recall_b, fvalue_b = prec_recall_fvalue(pred_roll_b, gt_roll_b,
                                                    thres)
    prec_o, recall_o, fvalue_o = prec_recall_fvalue(pred_roll_o, gt_roll_o,
                                                    thres)
    # EER for each tag : [ 'c', 'm', 'f', 'v', 'p', 'b', 'o', 'S' ]
    EER_c = eer.compute_eer('result.csv', 'c',
                            dict(zip(y_true_file_c, y_true_binary_c)))
    EER_m = eer.compute_eer('result.csv', 'm',
                            dict(zip(y_true_file_m, y_true_binary_m)))
    EER_f = eer.compute_eer('result.csv', 'f',
                            dict(zip(y_true_file_f, y_true_binary_f)))
    EER_v = eer.compute_eer('result.csv', 'v',
                            dict(zip(y_true_file_v, y_true_binary_v)))
    EER_p = eer.compute_eer('result.csv', 'p',
                            dict(zip(y_true_file_p, y_true_binary_p)))
    EER_b = eer.compute_eer('result.csv', 'b',
                            dict(zip(y_true_file_b, y_true_binary_b)))
    EER_o = eer.compute_eer('result.csv', 'o',
                            dict(zip(y_true_file_o, y_true_binary_o)))
    EER = (EER_c + EER_m + EER_v + EER_p + EER_f + EER_b + EER_o) / 7.0
    prec2 = (prec_c + prec_m + prec_f + prec_v + prec_p + prec_b +
             prec_o) / 7.0
    recall2 = (recall_c + recall_m + recall_f + recall_v + recall_p +
               recall_b + recall_o) / 7.0
    fvalue2 = (fvalue_c + fvalue_m + fvalue_f + fvalue_v + fvalue_p +
               fvalue_b + fvalue_o) / 7.0
    print prec, recall, fvalue
    print prec2, recall2, fvalue2
    print EER_c, EER_m, EER_f, EER_v, EER_p, EER_b, EER_o
    print prec_c, prec_m, prec_f, prec_v, prec_p, prec_b, prec_o
    print recall_c, recall_m, recall_f, recall_v, recall_p, recall_b, recall_o
    print fvalue_c, fvalue_m, fvalue_f, fvalue_v, fvalue_p, fvalue_b, fvalue_o
    print EER