def main():
    os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = '0'
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    time_list = []
    for i in range(5):# 5 runs for average
        args.id = str(i)# id
        tf.reset_default_graph()
        with tf.Session(config=config) as sess:
            args.result = os.path.join(args.result, args.id)
            args.log = os.path.join(args.log, args.id)
            args.model = os.path.join(args.model, args.id)
            args.tfrecords = os.path.join(args.tfrecords, args.id)
            if not os.path.exists(args.model):
                os.mkdir(args.model)
            if not os.path.exists(args.log):
                os.mkdir(args.log)
            if not os.path.exists(args.result):
                os.mkdir(args.result)
            if not os.path.exists(args.tfrecords):
                os.mkdir(args.tfrecords)

            data_model = Data(args)
            data_model.read_data()
            dataset_train = data_model.data_parse(
                os.path.join(args.tfrecords, 'train_data.tfrecords'), type='train')
            dataset_test = data_model.data_parse(
                os.path.join(args.tfrecords, 'test_data.tfrecords'), type='test')
            dataset_sae_train = data_model.data_parse(
                os.path.join(args.tfrecords, 'sae_train_data_' + str(args.sae_ratio) + '.tfrecords'), type='sae_train')
            dataset_sae_test = data_model.data_parse(
                os.path.join(args.tfrecords, 'sae_test_data.tfrecords'), type='sae_test')
            dataset_de_map = data_model.data_parse(
                os.path.join(args.tfrecords, 'demap_data' + '.tfrecords'), type='demap')

            model = Model(args,sess)
            if args.load_model:
                model.load(args.model)
            else:
                model.train(dataset_train,dataset_sae_train,data_model)
            a = datetime.now()
            model.test(dataset_test)
            b = datetime.now()
            time_list.append((b-a).total_seconds())
            if args.get_decode_map:
                model.save_decode_map(dataset_de_map)
            if args.get_decode_image:
                model.get_decode_image(dataset_sae_test)
            if args.get_feature:
                model.get_feature(dataset_sae_test)
            args.result = 'result'
            args.log = 'log'
            args.tfrecords = 'tfrecords'
            args.model = 'model'
Beispiel #2
0
def main():

    os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = '0'
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True

    for i in range(1):
        args.id = str(i)
        tf.reset_default_graph()
        with tf.Session(config=config) as sess:
            args.result = os.path.join(args.result, args.id)
            args.log = os.path.join(args.log, args.id)
            args.model = os.path.join(args.model, args.id)
            args.tfrecords = os.path.join(args.tfrecords, args.id)
            if not os.path.exists(args.model):
                os.mkdir(args.model)
            if not os.path.exists(args.log):
                os.mkdir(args.log)
            if not os.path.exists(args.result):
                os.mkdir(args.result)
            if not os.path.exists(args.tfrecords):
                os.mkdir(args.tfrecords)

            dataset = Data(args)
            dataset.read_data()
            train_dataset = dataset.data_parse(os.path.join(
                args.tfrecords, 'train_data.tfrecords'),
                                               type='train')
            test_dataset = dataset.data_parse(os.path.join(
                args.tfrecords, 'test_data.tfrecords'),
                                              type='test')
            map_dataset = dataset.data_parse(os.path.join(
                args.tfrecords, 'map_data.tfrecords'),
                                             type='map')

            model = Model(args, sess)
            if not args.load_model:
                model.train(train_dataset)
            else:
                model.load(args.model)
            model.test(test_dataset)
            if args.save_decode_map:
                model.save_decode_map(map_dataset)
            args.result = 'result'
            args.log = 'log'
            args.tfrecords = 'tfrecords'
            args.model = 'model'
Beispiel #3
0
def main(num, run_num):

    os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = '0,1,2'
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    overall_oa = []  # used to store OA
    overall_aa = []  # used to store AA
    overall_kappa = []  # used to store Kappa
    overall_matrix = [
    ]  # used to Used to store the resulting obfuscation matrix
    for j in range(num):  # In this experiment, num is 20
        print('第' + str(j + 1) + "次运行:")
        for i in range(1):
            args.id = str(i)
            tf.reset_default_graph()
            with tf.Session(config=config) as sess:
                args.result = os.path.join(args.result, args.id)
                args.log = os.path.join(args.log, args.id)
                args.model = os.path.join(args.model, args.id)
                args.tfrecords = os.path.join(args.tfrecords, args.id)
                if not os.path.exists(args.model):
                    os.mkdir(args.model)
                if not os.path.exists(args.log):
                    os.mkdir(args.log)
                if not os.path.exists(args.result):
                    os.mkdir(args.result)
                if not os.path.exists(args.tfrecords):
                    os.mkdir(args.tfrecords)

                dataset = Data(args)
                #test_pos_all is used to draw a diagram with no background
                test_pos_all = dataset.read_data()
                # producing training dataset
                train_dataset = dataset.data_parse(os.path.join(
                    args.tfrecords, 'train_data.tfrecords'),
                                                   type='train')
                # producing testing dataset, or producing during use.
                test_dataset = dataset.data_parse(os.path.join(
                    args.tfrecords, 'test_data.tfrecords'),
                                                  type='test')
                #all_dataset = dataset.data_parse(os.path.join(args.tfrecords, 'map_data.tfrecords'), type='map')

                model = Model(args, sess)
                # traing the model
                if not args.load_model:
                    model.train(train_dataset, dataset)
                else:
                    model.load(args.model)
                # the model return the result of experiments once.
                oa, aa, kappa, matrix, result_label = model.test(dataset)
                # Calculated running time
                over = time.time()
                print("平均运行时间:  " + str((over - start) / 60.0) + " min")
                #create_All_label(model,args.data_name,dataset,j) # draw picture containing background
                #decode_map(test_pos_all, result_label,args.data_name) # draw picture not containing background
                overall_oa.append(oa)
                overall_aa.append(aa)
                overall_kappa.append(kappa)
                overall_matrix.append(matrix)
                args.result = 'result'
                args.log = 'log'
                args.tfrecords = 'tfrecords'
                args.model = 'model'
    # Store the results of the experiment locally
    if not os.path.exists(str(pathlib.Path(args.data_name))):
        os.mkdir(str(pathlib.Path(args.data_name)))
    sio.savemat(
        os.path.join(str(pathlib.Path(args.data_name)),
                     'result' + str(run_num) + '.mat'), {
                         'oa': overall_oa,
                         'aa': overall_aa,
                         'kappa': overall_kappa
                     })
    sio.savemat(
        os.path.join(str(pathlib.Path(args.data_name)),
                     'matrix' + str(run_num) + '.mat'),
        {'matrix': overall_matrix})
def main():
    os.environ['CUDA_DEVICE_ORDER'] = 'PCI_BUS_ID'
    os.environ['CUDA_VISIBLE_DEVICES'] = '5'
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    time_list = []
    for i in range(1):
        args.id = str(i)# id
        tf.reset_default_graph()
        with tf.Session(config=config) as sess:
            args.result = os.path.join(args.result, args.id)
            args.log = os.path.join(args.log, args.id)
            args.model = os.path.join(args.model, args.id)
            args.tfrecords = os.path.join(args.tfrecords, args.id)
            if not os.path.exists(args.model):
                os.mkdir(args.model)
            if not os.path.exists(args.log):
                os.mkdir(args.log)
            if not os.path.exists(args.result):
                os.mkdir(args.result)
            if not os.path.exists(args.tfrecords):
                os.mkdir(args.tfrecords)
            print("##################### Loading Data!! #####################")
            data_model = Data(args)
            data_model.read_data()
            dataset_train = data_model.data_parse(
                os.path.join(args.tfrecords, 'train_data.tfrecords'), type='train')    
            dataset_test = data_model.data_parse(
                os.path.join(args.tfrecords, 'test_data.tfrecords'), type='test')
            dataset_sae_train = data_model.data_parse(
                os.path.join(args.tfrecords, 'sae_train_data_' + str(args.sae_ratio) + '.tfrecords'), type='sae_train')
            dataset_sae_test = data_model.data_parse(
                os.path.join(args.tfrecords, 'sae_test_data.tfrecords'), type='sae_test')
            dataset_de_map = data_model.data_parse(
                os.path.join(args.tfrecords, 'demap_data' + '.tfrecords'), type='demap')
            print("##################### Data_Load Finished!! #####################")
            #print("dataset_train:",dataset_train)
            # dataset_train = tf.reshape(dataset_train, shape=[-1,220])
            print("dataset_train:",type(dataset_train)) #(?, 1, 1, 220, 1)
            model = Model(args,sess)
            if args.load_model:
                model.load(args.model)
            else:
                model.train(dataset_train,dataset_sae_train,data_model)
            a = datetime.now()
            model.test(dataset_test)
            b = datetime.now()
            time_list.append((b-a).total_seconds())
            if args.get_decode_map:
                model.save_decode_map(dataset_de_map)
            #if args.get_decode_image:
            #    model.get_decode_image(dataset_sae_test)
            #if args.get_feature:
            #    model.get_feature(dataset_sae_test)
            args.result = 'result'
            args.log = 'log'
            args.tfrecords = 'tfrecords'
            args.model = 'model'
            print("Begin write time!....")
            f = open(os.path.join(args.result,'time.txt'),'a')
            f.write(str(time_list))
            f.close()
            sio.savemat(os.path.join(args.result,'time.mat'),{'time_list':time_list})
            print("END!....")