Ejemplo n.º 1
0
def main():
    start = datetime.datetime.now()
    if not os.path.exists(args.checkpoint_dir):
        os.makedirs(args.checkpoint_dir)
    if not os.path.exists(args.sample_dir):
        os.makedirs(args.sample_dir)
    if not os.path.exists(args.test_dir):
        os.makedirs(args.test_dir)
    if not os.path.exists(args.train_dir):
        os.makedirs(args.train_dir)
    tf.reset_default_graph()
    with tf.Session() as sess:
        model = graph2graph(sess,
                            batch_size=args.batch_size,
                            checkpoint_dir=args.checkpoint_dir,
                            sample_dir=args.sample_dir,
                            test_dir=args.test_dir,
                            train_dir=args.train_dir,
                            graph_size=args.graph_size,
                            output_size=args.output_size,
                            dataset=args.dataset)

        model.train(args)
    end = datetime.datetime.now()
    print(end - start)
Ejemplo n.º 2
0
def main(_):
    if not os.path.exists(args.checkpoint_dir):
        os.makedirs(args.checkpoint_dir)
    tf.reset_default_graph()
    with tf.Session() as sess:
        model = graph2graph(sess,
                            Ds=args.Ds,
                            No=args.No,
                            Nr=args.Nr,
                            Dr=args.Dr,
                            Dx=args.Dx,
                            De_o=args.De_o,
                            De_r=args.De_r,
                            Mini_batch=args.Mini_batch,
                            checkpoint_dir=args.checkpoint_dir,
                            epoch=args.epoch,
                            Ds_inter=args.Ds_inter,
                            Dr_inter=args.Dr_inter)
        if args.Type == 'train':
            model.train(args)
        if args.Type == 'test':
            start = datetime.datetime.now()
            model.test(args)
            end = datetime.datetime.now()
            print(end - start)
Ejemplo n.º 3
0
def main_auth(filename):
    #start = datetime.datetime.now()
    if not os.path.exists(args.checkpoint_dir):
        os.makedirs(args.checkpoint_dir)
    if not os.path.exists(args.sample_dir):
        os.makedirs(args.sample_dir)
    if not os.path.exists(args.test_dir):
        os.makedirs(args.test_dir)
    tf.reset_default_graph()
    with tf.Session() as sess:
        model = graph2graph(sess,
                            batch_size=args.batch_size,
                            checkpoint_dir=args.checkpoint_dir,
                            sample_dir=args.sample_dir,
                            test_dir=args.test_dir,
                            train_dir=args.train_dir,
                            graph_size=args.graph_size,
                            output_size=args.output_size)
        #model.train(args)
        model.test_auth(args, filename)
Ejemplo n.º 4
0
def main():
    start = datetime.datetime.now()
    if not os.path.exists(args.checkpoint_dir):
        os.makedirs(args.checkpoint_dir)
    if not os.path.exists(args.sample_dir):
        os.makedirs(args.sample_dir)
    if not os.path.exists(args.test_dir):
        os.makedirs(args.test_dir)

    #with tf.Session() as sess:
    #model = graph2graph(sess, batch_size=args.batch_size,checkpoint_dir=args.checkpoint_dir,sample_dir=args.sample_dir,test_dir=args.test_dir,train_dir=args.train_dir,graph_size=args.graph_size,output_size=args.output_size, dataset=args.dataset)
    v1 = np.load('data1s.npy')
    v4 = np.load('data2s.npy')

    predicted = np.zeros(shape=(30, 1225))  #  full predicted  dataset
    ground = np.zeros(shape=(
        30, 1225
    ))  #  structure for test data (unused for traınıng) ın each ıteratıon
    #loo = KFold(n_splits=5)
    #loo.get_n_splits(v1)

    #KFold(n_splits=6, random_state=None, shuffle=False)
    from sklearn.model_selection import KFold
    loo = KFold(n_splits=5)

    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    session = tf.Session(config=config)
    option = None

    #TF_CONFIG = tf.ConfigProto(gpu_options=tf.GPUOptions(per_process_gpu_memory_fraction=0.5),allow_soft_placement=True)

    #sess = tf.Session(config=TF_CONFIG)

    pcr = []
    mser = []
    pv = []
    predicteddata = []
    wholepredicted = []
    for train_index, test_index in loo.split(v1):
        tf.reset_default_graph()
        with tf.Session() as sess:
            model = graph2graph(sess,
                                batch_size=args.batch_size,
                                checkpoint_dir=args.checkpoint_dir,
                                sample_dir=args.sample_dir,
                                test_dir=args.test_dir,
                                train_dir=args.train_dir,
                                graph_size=args.graph_size,
                                output_size=args.output_size,
                                dataset=args.dataset)

            #epoch=args.epoch
            ##cuda.select_device(0)

            reg1, reg2 = v1[train_index], v1[
                test_index]  #  reg1 ıs v1 traın dataset, reg2 v1 testdataset
            print(np.shape(reg1), 'reg1')
            print(np.shape(reg2), 'reg2')
            mal1, mal2 = v4[train_index], v4[
                test_index]  #mal1:v4 traın dataset,mal2 v4 testdataset(lıke y traın and test

            datatrain = np.zeros((reg1.shape[0], reg1.shape[1], reg1.shape[2],
                                  2))  #  forming a paır of traın samples
            print('now the test index is', test_index)
            for i in range(reg1.shape[0]):
                datatrain[i, :, :, 0] = reg1[i]  ###reg1=train v1
                datatrain[i, :, :,
                          1] = mal1[i]  #mal1=train v2 (154, 35, 35, 2)
            print(np.shape(datatrain), 'thıs ıs traın data after loop')
            #model.train(args, datatrain)

            datatest = np.zeros((reg2.shape[0], reg2.shape[1], reg2.shape[2],
                                 2))  #  here we dont use any v4 data
            for i in range(reg2.shape[0]):
                datatest[i, :, :, 0] = reg2[i]
                datatest[i, :, :, 1] = reg2[
                    i]  #  forming a paır of test samples all from v1.

            print(predicted.shape)
            xx = model.test(args, datatest)
            predicted = xx.reshape(
                -1, 1225
            )  #   predicted[test_index,:] fill predicted with current test_index
            ground = np.reshape(
                mal2, (-1, 1225)
            )  #  fill the previously defined predicted array with current test data

            sess.close()
            gc.collect()
            print(predicted.shape, ground.shape)
            corr, pvalue = pearsonr(predicted.ravel(), ground.ravel())
            mse = mean_squared_error(predicted, ground)
            pcr.append(corr)
            pv.append(pvalue)
            mser.append(mse)
            predicteddata.append(predicted)
            wholepredicted.append(predicted)
            np.savetxt("./pred/pred" + str(test_index[0]) + ".txt",
                       predicted,
                       delimiter=',')
            np.savetxt("./gt/gt" + str(test_index[0]) + ".txt",
                       ground,
                       delimiter=',')

            print("pearson corr ", corr)
            print("pvalue ", pvalue)
            print("mean square error ", mse)
            end = datetime.datetime.now()
            print(start, 'thıs ıs the start tıme')
            print(end, 'thıs ıs the end  tıme')
            print('total tıme ıs', start - end)
            gc.collect()

        tf.reset_default_graph()

    with open("./savedrestc/pcr rhv4 to v3last.txt", "w") as f:
        for s in pcr:
            f.write(str(s) + "\n")
    with open("./savedrestc/mser rhv4 to v3last.txt", "w") as f:
        for p in mser:
            f.write(str(p) + "\n")
    with open("./savedrestc/pv rhv4 to v3last.txt", "w") as f:
        for v in pv:
            f.write(str(v) + "\n")
    with open("./predwhole/predwhole.txt", "w") as f:
        for w in predicteddata:
            f.write(str(w) + "\n")

    #pv_mean=pv/5
    pcr_mean = sum(pcr) / len(pcr)
    print("length of pv is ", len(pv))
    print("length of pcr is ", len(pcr))
    mse_mean = sum(mser) / len(mser)
    pv_mean = sum(pv) / len(pv)
    print(predicted.shape, ground.shape)
    corr, pvalue = pearsonr(predicted.ravel(), ground.ravel())
    mse = mean_squared_error(predicted, ground)
    print("pearson corr ", corr)
    print("mean square error ", mse)
    print("Now mean results  ")
    print("pearson corr_mean ", pcr_mean)
    print("mean square error_mean ", mse_mean)
    print("pv_mean is ", pv_mean)
    end = datetime.datetime.now()
    print(start, 'thıs ıs the start tıme')
    print(end, 'thıs ıs the end  tıme')
    print('total tıme ıs', start - end)
    #np.savetxt("./predwhole/predicted3d.txt.txt",predicteddata)
    predicteddata2d = predicteddata[1:2]
    predicted2d = np.reshape(predicteddata2d, (30, 1225))
    np.savetxt("./predwhole/2dpredicted.txt", predicted2d)
    np.save("./predwhole/wholepredicteddata.npy", wholepredicted)
Ejemplo n.º 5
0
def main():
    start = datetime.datetime.now()
    if not os.path.exists(args.checkpoint_dir):
        os.makedirs(args.checkpoint_dir)
    if not os.path.exists(args.sample_dir):
        os.makedirs(args.sample_dir)
    if not os.path.exists(args.test_dir):
        os.makedirs(args.test_dir)

    v1=np.load('graph_view1.npy')#150, 35, 35
    v4=np.load('graph_view2.npy')
    n_splits = 5
    predicted = np.zeros(shape=(int(v1.shape[0]/n_splits),v1.shape[1]*v1.shape[2]))#  full predicted  dataset
    ground = np.zeros(shape=(int(v1.shape[0]/n_splits),v1.shape[1]*v1.shape[2])) #  structure for test data
    predicted2 = np.zeros(shape=(int(v1.shape[0]/n_splits),v1.shape[1]*v1.shape[2]))
    ground2 = np.zeros(shape=(int(v1.shape[0]/n_splits),v1.shape[1]*v1.shape[2]))
    from sklearn.model_selection import KFold
    loo=KFold(n_splits=5)
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    session = tf.Session(config=config)
    option=None
    pcr=[]
    mser=[]
    pv=[]
    predicteddata=[]
    wholepredicted=[]
    pcr2=[]
    mser2=[]
    pv2=[]
    predicteddata2=[]
    wholepredicted2=[]
    for train_index, test_index in loo.split(v1):
        tf.reset_default_graph()
        with tf.Session() as sess:
            model = graph2graph(sess, batch_size=args.batch_size,
                checkpoint_dir=args.checkpoint_dir, sample_dir=args.sample_dir,test_dir=args.test_dir,train_dir=args.train_dir,graph_size=args.graph_size,output_size=args.output_size, dataset=args.dataset)
            reg1, reg2 = v1[train_index], v1[test_index]#  reg1 ıs v1 traın dataset, reg2 v1 testdataset
            print(np.shape(reg1),'reg1')
            print(np.shape(reg2),'reg2')
            mal1, mal2 = v4[train_index], v4[test_index]#mal1:v4 traın dataset,mal2 v4 testdataset
            datatrain=np.zeros((reg1.shape[0],reg1.shape[1],reg1.shape[2],2)) #  forming a paır of traın samples
            print('now the test index is', test_index)
            for i in range(reg1.shape[0]):
                datatrain[i,:,:,0]=reg1[i]  ###reg1=train v1  reg ıs A   and mal ıs B
                datatrain[i,:,:,1]=mal1[i]
            model.train(args, datatrain)
            # prediction in the first direction
            datatest=np.zeros((reg2.shape[0],reg2.shape[1],reg2.shape[2],2))
            for i in range(reg2.shape[0]):
                datatest[i,:,:,0]=reg2[i]
                datatest[i,:,:,1]=reg2[i]#  forming a paır of test samples, first direction prediction.
            print(predicted.shape)
            xx=model.test(args,   datatest)
            predicted = xx.reshape(-1,v1.shape[1]*v1.shape[2])
            ground = np.reshape(mal2, (-1,v1.shape[1]*v1.shape[2]))
            print(predicted.shape,ground.shape)
            corr,pvalue = pearsonr(predicted.ravel(),ground.ravel())
            mse=mean_squared_error(predicted,ground)
            pcr.append(corr)
            pv.append(pvalue)
            mser.append(mse)
            predicteddata.append(predicted)
            wholepredicted.append(predicted)
            print("pearson corr ", corr)
            print("pvalue ", pvalue)
            print("mean square error ",mse)
            # prediction in opposite direction (second direction)
            print('###### begin B to A#####')
            datatest2=np.zeros((mal2.shape[0],mal2.shape[1],mal2.shape[2],2))  #
            for i in range(reg2.shape[0]):
                datatest2[i,:,:,0]=mal2[i]
                datatest2[i,:,:,1]=mal2[i]#  forming a paır of test samples.
            print(predicted2.shape)
            xx=model.test2(args,   datatest2)
            predicted2 = xx.reshape(-1,v1.shape[1]*v1.shape[2])
            ground2 = np.reshape(reg2, (-1,v1.shape[1]*v1.shape[2]))

            sess.close()
            gc.collect()
            print(predicted2.shape,ground2.shape)
            corr2,pvalue2 = pearsonr(predicted2.ravel(),ground2.ravel())
            mse2=mean_squared_error(predicted2,ground2)
            pcr2.append(corr2)
            pv2.append(pvalue2)
            mser2.append(mse2)
            predicteddata2.append(predicted2)
            wholepredicted2.append(predicted2)
            print("pearson corr ", corr2)
            print("pvalue ", pvalue2)
            print("mean square error ",mse2)

            print('###### end of B to A#######')
            end = datetime.datetime.now()
            print (start, 'thıs ıs the start tıme')
            print (end, 'thıs ıs the end  tıme')

            gc.collect()

        tf.reset_default_graph()
    pcr_mean=sum(pcr) / len(pcr)
    print("length of pv is ", len(pv))
    print("length of pcr is ", len(pcr))
    mse_mean=sum(mser) / len(mser)
    pv_mean =sum(pv) / len(pv)
    print(predicted.shape,ground.shape)

    print("****Now mean results A to B**** ")
    print("pearson corr_mean ", pcr_mean)
    print("mean square error_mean ",mse_mean)
    print("pv_mean is ",pv_mean)
    end = datetime.datetime.now()
    print (start, 'thıs ıs the start tıme')
    print (end, 'thıs ıs the end  tıme')
    np.save("wholepredicted_atob.npy", wholepredicted)
    print('################## beginning of second part B to A #############################################')
    pcr_mean2=sum(pcr2) / len(pcr2)
    mse_mean2=sum(mser2) / len(mser2)
    pv_mean2 =sum(pv2) / len(pv2)

    print("****Now mean results for B to A **** ")
    print("pearson corr_mean_B to A ", pcr_mean2)
    print("mean square error_mean_B to A ",mse_mean2)
    print("pv_mean is ",pv_mean2)
    np.save("wholepredicted_btoa.npy", wholepredicted2)
    print('################## end of second part B to A #############################################')
    end = datetime.datetime.now()
    print (start, 'thıs ıs the start tıme')
    print (end, 'thıs ıs the end  tıme')
    print ('total tıme ıs', start-end)