Пример #1
0
 def test_script(self, execute_manager):
     # The test script should execute the standard Django test
     # command with any apps given as its arguments.
     test.main('cheeseshop.development',  'spamm', 'eggs')
     # We only care about the arguments given to execute_manager
     self.assertEqual(execute_manager.call_args[1],
                      {'argv': ['test', 'test', 'spamm', 'eggs']})
Пример #2
0
    def test_deeply_nested_settings(self, execute_manager):
        # Settings files can be more than two levels deep. We need to
        # make sure the test script can properly import those. To
        # demonstrate this we need to add another level to our
        # sys.modules entries.
        settings = mock.sentinel.SettingsModule
        nce = mock.sentinel.NCE
        nce.development = settings
        sys.modules['cheeseshop'].nce = nce
        sys.modules['cheeseshop.nce'] = nce
        sys.modules['cheeseshop.nce.development'] = settings

        test.main('cheeseshop.nce.development',  'tilsit', 'stilton')
        self.assertEqual(execute_manager.call_args[0], (settings,))
Пример #3
0
def run():
	global USE_GPUS
	val_num = np.random.randint(1, 6)
	cifar10_input.set_constants(train=True, val_num=val_num)
	if USE_GPUS:			
		import cifar10_multi_gpu_train
		cifar10_multi_gpu_train.main()
	else:
		import cifar10_train
		cifar10_train.main()
	if TEST:
		test.main()
	else:
		cifar10_input.set_constants(train=False, val_num=val_num)
		cifar10_eval.main()
Пример #4
0
 def run_tests(self):
     # import here, because outside the eggs aren't loaded
     here = os.path.abspath(os.path.dirname(__file__))
     sys.path.insert(0, os.path.join(here, 'test'))
     import test
     errno = test.main(self.pytest_args.split())
     sys.exit(errno)
Пример #5
0
def exampleSetup(): 
	import test
	data4,data5,handover_starts,l0,U0,l1,U1e,U1,l2,U2,U2e,ainds,alabs = test.main()

	def loader(handover_starts,data_object,n): 
		try: 
			starts = [handover_starts[n],handover_starts[n+1]]
		except IndexError: 
			starts = [handover_starts[n],data_object.num_vectors-1]
		return starts

	def runTasks(data_obj,task_obj,n,max_ind=10): 
		inds = np.random.randint(max_ind,size=n)
		for i in inds: 
			task_obj.update(data_obj,loader(handover_starts,data_obj,i))

	#initializing a task for the data4 object then showing the times for each path member
	task = Task(data4,loader(handover_starts,data4,0))
	print task.times
	out = task.printTaskDef()

	#updating a task for the data4 object then showing the times for each path member
	task.update(data4,loader(handover_starts,data4,1))
	print task.times
	out = task.printTaskDef()

	#or can do: 
	task = Task(data4,loader(handover_starts,data4,0))
	n = 20 #run 20 random updates from the handover set
	runTasks(data4,task,n,max_ind=11)
Пример #6
0
from utils import *
import test

if __name__ == "__main__":
    kwargs = get_init_arguments()
    test.main(**kwargs)
Пример #7
0
import pyximport; pyximport.install()
from test import main

main()
Пример #8
0
from test import main

from .graphics.test_histogram_mpl import *
from .serialization.test_histogram_hist import *
from .serialization.test_histogram_hdf5 import *
from .serialization.test_histogram_numpy import *
from .serialization.test_histogram_root import *
from .serialization.test_serialization import *
from .test_histogram import *
from .test_histogram_axis import *
from .test_run_control import *

main()
Пример #9
0
        
        total_run_time += time_use

    tree_information = {
        'max_depth': master.max_depth,
        'min_bag_size': master.min_bag_size,
        'total_run_time': total_run_time,
        'avg_run_time': total_run_time/(number_of_tree*1.0),
        'file_list': file_list
    }

    with open(os.path.join(tree_root_folder, mainfile), 'w') as f:
        json.dump(tree_information, f, indent=2)

    print('\n{} Tree(s) creation successful'.format(number_of_tree))
    print('Total run time: {} sec'.format(total_run_time))
    print('Avg run time per tree: {} sec'.format(1.0*total_run_time/number_of_tree*1.0))

if __name__ == '__main__':
    if len(sys.argv) < 3:
        print('Usage: {} <main JSON file name> <dataset file> [optional:number of tree]')
        sys.exit(1)
    elif len(sys.argv) == 3:
        main(sys.argv[1], sys.argv[2])
    elif len(sys.argv) == 4:
        main(sys.argv[1], sys.argv[2], int(sys.argv[3]))

    clmax = 5

    test.main(clmax, os.path.join(tree_root_folder, sys.argv[1]))
Пример #10
0
# --------------------------------------------------------
# Deformable Convolutional Networks
# Copyright (c) 2017 Microsoft
# Licensed under The MIT License [see LICENSE for details]
# Written by Haozhi Qi
# --------------------------------------------------------
import os
import sys
os.environ['PYTHONUNBUFFERED'] = '1'
os.environ['MXNET_CUDNN_AUTOTUNE_DEFAULT'] = '0'
os.environ['MXNET_ENABLE_GPU_P2P'] = '0'
# os.environ['MXNET_ENGINE_TYPE'] = 'NaiveEngine'
this_dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(this_dir, '..', '..', 'fpn'))

import train_end2end
import test

if __name__ == "__main__":
    train_end2end.main()
    test.main()




def main(args, hpnames):

    # separate mode or best score mode
    repetition = 1
    if args.separate_mode:
        repetition = args.repetition
        args.repetition = 1  # separate model (non best score model)

    # TODO: record model configuration in checkpoint
    if len(args.tracker.model.backbone.return_layers) == 0:
        args.tracker.model.backbone.return_layers = ['layer3']

    if len(args.tracker.dcf.layers) == 0:
        args.tracker.dcf.layers = ['layer2', 'layer3']

    # create dir for result
    layers_info = 'trtr_layer'
    for layer in args.tracker.model.backbone.return_layers:
        layers_info += '_' + layer[-1]
    if args.use_baseline_tracker:
        layers_info += '_baseline'
    else:
        layers_info += '_dcf_layer'
        for layer in args.tracker.dcf.layers:
            layers_info += '_' + layer[-1]

    if args.separate_mode:
        args.save_path += '_separate'
    args.result_path = os.path.join(
        args.save_path,
        os.path.splitext(os.path.basename(args.tracker.checkpoint))[0],
        layers_info)
    dataset_path = os.path.join(args.result_path, args.dataset)
    if not os.path.isdir(dataset_path):
        os.makedirs(dataset_path)

    hparams = dict()
    for name in hpnames:

        val = args
        for idx, n in enumerate(name.split('.')):

            if idx == len(name.split('.')) - 1:
                default_value = getattr(val, n[:-1])

            val = getattr(val, n)

        if len(val) == 0:
            hparams[name] = [default_value]
        else:
            hparams[name] = [type(default_value)(v) for v in val]
    hparams['runs'] = list(range(1, repetition + 1))

    tracker_num = len(list(itertools.product(*hparams.values())))

    for tracker_id, hparam_set in enumerate(
            itertools.product(*hparams.values())):
        t = time.time()
        print("start {}/{} tracker test".format(tracker_id + 1, tracker_num))
        model_name = ''
        if args.use_baseline_tracker:
            model_name = 'baseline_'
        for idx, (name, val) in enumerate(zip(hparams.keys(), hparam_set)):

            args_temp = args
            for str_id, n in enumerate(name[:-1].split('.')):
                if str_id == len(name.split('.')) - 1:
                    setattr(args_temp, n, val)

                args_temp = getattr(args_temp, n)

            if args.use_baseline_tracker and 'dcf' in name:
                continue

            model_name += name[:-1].replace('tracker.', '').replace(
                'postprocess.', '').replace('.', '_') + "_" + str(val).replace(
                    '.', 'p')
            if idx < len(hparam_set) - 1:
                model_name += '_'

        if not args.use_baseline_tracker:
            model_name += '_false_positive'  # workaround to distinguish with old model name

        if args.tracker.model.transformer_mask:
            model_name += '_with_transformer_mask'

        #print(model_name)
        model_dir = os.path.join(dataset_path, model_name)
        if not os.path.isdir(model_dir):
            os.makedirs(model_dir)

        args.model_name = model_name
        with open(os.path.join(model_dir, 'log.txt'), 'a') as f:
            f.write('parameters: \n')
            f.write('{}'.format(vars(args)) + '\n\n')

        # create tracker
        if args.use_baseline_tracker:
            tracker = build_baseline_tracker(args.tracker)
        else:
            tracker = build_online_tracker(args.tracker)

        # start test with benchmark
        benchmark.main(args, tracker)

        du = round(time.time() - t)
        print("finish {}/{} tracker test, take {}, rest {} ".format(
            tracker_id + 1, tracker_num, datetime.timedelta(seconds=du),
            datetime.timedelta(seconds=du * (tracker_num - tracker_id - 1))))
Пример #12
0
                r += k
                i += len(k)
                break
        else:
            if not s[i].isspace():
                r += s[i]
            i += 1
    print(r)
with open("liczba-min.cpp", "w") as file:
    file.write(r)

print("= Compiling =")
compile_ok = 0 == system(
    "g++ -O2 -pedantic -Wextra -Wall -std=c++98 -c liczba-min.cpp -o liczba-min.o"
)
if compile_ok:
    compile_ok = 0 == system(
        "g++ -O2 -pedantic -Wextra -Wall -std=c++98 -o liczba-min.exe liczba-min.o"
    )
if compile_ok:
    print("= Testing =")
    test_ok = test.main("liczba-min.exe", False)
else:
    test_ok = None
if compile_ok and test_ok:
    print("Success!")
    print(f"Length: {len(r)}")
else:
    print("Failure.")
    print(f"Compilation OK: {compile_ok}\nTests OK: {test_ok}")
system("pause")
Пример #13
0
def main():
    usage = "Usage: vcfPytools.py [tool] [options]\n\n" + \
            "Available tools:\n" + \
            "  annotate:\n\tAnnotate the vcf file with membership in other vcf files.\n" + \
            "  extract:\n\tExtract vcf records from a region.\n" + \
            "  filter:\n\tFilter the vcf file.\n" + \
            "  indel:\n\tIndel manipulation tools.\n" + \
            "  intersect:\n\tGenerate the intersection of two vcf files.\n" + \
            "  merge:\n\tMerge a list of vcf files.\n" + \
            "  multi:\n\tFind the intersections and unique fractions of multiple vcf files.\n" + \
            "  sort:\n\tSort a vcf file.\n" + \
            "  stats:\n\tGenerate statistics from a vcf file.\n" + \
            "  union:\n\tGenerate the union of two vcf files.\n" + \
            "  unique:\n\tGenerate the unique fraction from two vcf files.\n" + \
            "  validate:\n\tValidate the input vcf file.\n\n" + \
            "vcfPytools.py [tool] --help for information on a specific tool."

    # Determine the requested tool.

    if len(sys.argv) > 1:
        tool = sys.argv[1]
    else:
        print >> sys.stderr, usage
        exit(1)

    if tool == "annotate":
        import annotate
        success = annotate.main()
    elif tool == "extract":
        import extract
        success = extract.main()
    elif tool == "filter":
        import filter
        success = filter.main()
    elif tool == "intersect":
        import intersect
        success = intersect.main()
    elif tool == "indel":
        import indel
        success = indel.main()
    elif tool == "multi":
        import multi
        success = multi.main()
    elif tool == "merge":
        import merge
        success = merge.main()
    elif tool == "sort":
        import sort
        success = sort.main()
    elif tool == "stats":
        import stats
        success = stats.main()
    elif tool == "union":
        import union
        success = union.main()
    elif tool == "unique":
        import unique
        success = unique.main()
    elif tool == "test":
        import test
        success = test.main()
    elif tool == "validate":
        import validate
        success = validate.main()
    elif tool == "--help" or tool == "-h" or tool == "?":
        print >> sys.stderr, usage
    else:
        print >> sys.stderr, "Unknown tool: ", tool
        print >> sys.stderr, "\n", usage
        exit(1)


# If program completed properly, terminate.

    if success == 0: exit(0)
Пример #14
0
def compute_termfreq(list_top_k, file_path):
    return test.main(list_top_k, file_path)
Пример #15
0
opt.kps = info.kps

if not if_exist:
    csv_writer.writerow(write_test_title())

for op, mdl, name, fold in zip(option_ls, model_ls, name_ls, folder_ls):
    log = [fold, name]

    info = torch.load(op)
    cfg = info.struct
    backbone = info.backbone
    opt.kps = info.kps
    opt.DUC = info.DUC

    print("Testing model {}".format(mdl))
    benchmark, overall, part, thresholds = main(backbone, cfg, test_data, mdl)

    for item in benchmark:
        log.append(item)
    log.append(computer)

    for item in overall:
        if isinstance(item, torch.Tensor):
            item = item.tolist()
        log.append(item)
    log.append(" ")

    for indicator in part:
        for kp in indicator:
            if isinstance(kp, torch.Tensor):
                kp = kp.tolist()
Пример #16
0
def google():
    main()
    if False:
        from test2 import main
Пример #17
0
def _parse_args():
    parser = argparse.ArgumentParser(description="Run Bert finetune for qa")

    parser.add_argument('data_folder',
                        type=Path,
                        help='./release2/test/ca_data')
    parser.add_argument('--config_path',
                        type=Path,
                        help='config_path',
                        default="./dataset")
    parser.add_argument(
        '--model_path',
        type=str,
        help='model_path',
        default="./lightning_logs/version_63/checkpoints/epoch=1.ckpt")
    parser.add_argument('--predict_path',
                        type=str,
                        help='predict_path',
                        default="./prediction.csv")

    args = parser.parse_args()
    return args


if __name__ == '__main__':
    args = _parse_args()
    combine_lines.main(args)
    preprocess.main(args)
    test.main(args)
Пример #18
0
def main():
    essay_name = [
        1, 6, 7, 8, 13, 15, 16, 17, 21, 22, 23, 24, 25, 26, 27, 28, 29, 10, 14,
        37, 38, 39, 40, 41, 42, 43, 44, 45, 46
    ]
    test_essays = [
        1, 9, 11, 12, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 62, 63
    ]
    uni_essay_list = []
    bi_essay_list = []
    tri_essay_list = []

    read_files(uni_essay_list, 1, essay_name)
    read_files(bi_essay_list, 2, essay_name)
    read_files(tri_essay_list, 3, essay_name)

    hamilton = ngram.model("HAMILTON", {}, {}, {}, {}, {})
    madison = ngram.model("HAMILTON", {}, {}, {}, {}, {})

    hamilton.unigram = ngram.unigram("HAMILTON", uni_essay_list)
    madison.unigram = ngram.unigram("MADISON", uni_essay_list)

    hamilton.bigram, hamilton.bigram_generate = ngram.bigram(
        "HAMILTON", bi_essay_list)
    madison.bigram, madison.bigram_generate = ngram.bigram(
        "MADISON", bi_essay_list)

    hamilton.trigram, hamilton.trigram_generate = ngram.trigram(
        "HAMILTON", tri_essay_list)
    madison.trigram, madison.trigram_generate = ngram.trigram(
        "MADISON", tri_essay_list)
    for i in range(2):
        hamilton_generate_uni_essay = ngram.unigram_generator(
            hamilton.unigram, sum(hamilton.unigram.values()))
        hamilton_generate_bi_essay = ngram.bigram_generator(
            hamilton.bigram_generate.copy())
        hamilton_generate_tri_essay = ngram.trigram_generator(
            hamilton.trigram_generate.copy())

        madison_generate_uni_essay = ngram.unigram_generator(
            madison.unigram, sum(madison.unigram.values()))
        madison_generate_bi_essay = ngram.bigram_generator(
            madison.bigram_generate.copy())
        madison_generate_tri_essay = ngram.trigram_generator(
            madison.trigram_generate.copy())

        print(
            "********************************** HAMILTON UNIGRAM ESSAY :**************************************"
        )
        print(hamilton_generate_uni_essay)
        print(
            "HAMILTON: ",
            test.unigram_test(hamilton_generate_uni_essay.split(" "),
                              hamilton.unigram,
                              sum(hamilton.unigram.values())))
        print(
            "MADISON: ",
            test.unigram_test(hamilton_generate_uni_essay.split(" "),
                              madison.unigram, sum(madison.unigram.values())),
            "\n")
        print(
            "********************************** HAMILTON BIGRAM ESSAY :**************************************"
        )
        print(hamilton_generate_bi_essay)
        print(
            "HAMILTON: ",
            test.bigram_test(hamilton_generate_bi_essay.split(" "),
                             hamilton.bigram, len(hamilton.bigram.keys()),
                             hamilton.unigram))
        print(
            "MADISON: ",
            test.bigram_test(hamilton_generate_bi_essay.split(" "),
                             madison.bigram, len(madison.bigram.keys()),
                             madison.unigram), "\n")

        print(
            "********************************** HAMILTON TRIGRAM ESSAY :**************************************"
        )
        print(hamilton_generate_tri_essay)
        print(
            "HAMILTON",
            test.trigram_test(hamilton_generate_tri_essay.split(" "),
                              hamilton.bigram, len(hamilton.trigram.keys()),
                              hamilton.trigram))
        print(
            "MADISON",
            test.trigram_test(hamilton_generate_tri_essay.split(" "),
                              madison.bigram, len(madison.trigram.keys()),
                              madison.trigram), "\n")

        print(
            "********************************** MADISON UNIGRAM ESSAY :**************************************"
        )
        print(madison_generate_uni_essay)
        print(
            "HAMILTON: ",
            test.unigram_test(madison_generate_uni_essay.split(" "),
                              hamilton.unigram,
                              sum(hamilton.unigram.values())))
        print(
            "MADISON: ",
            test.unigram_test(madison_generate_uni_essay.split(" "),
                              madison.unigram, sum(madison.unigram.values())),
            "\n")

        print(
            "********************************** MADISON BIGRAM ESSAY :**************************************"
        )
        print(madison_generate_bi_essay, "\n")
        print(
            "HAMILTON: ",
            test.bigram_test(madison_generate_bi_essay.split(" "),
                             hamilton.bigram, len(hamilton.bigram.keys()),
                             hamilton.unigram))
        print(
            "MADISON: ",
            test.bigram_test(madison_generate_bi_essay.split(" "),
                             madison.bigram, len(madison.bigram.keys()),
                             madison.unigram), "\n")

        print(
            "********************************** MADISON TRIGRAM ESSAY :**************************************"
        )
        print(madison_generate_tri_essay)
        print(
            "HAMILTON",
            test.trigram_test(madison_generate_tri_essay.split(" "),
                              hamilton.bigram, len(hamilton.trigram.keys()),
                              hamilton.trigram))
        print(
            "MADISON",
            test.trigram_test(madison_generate_tri_essay.split(" "),
                              madison.bigram, len(madison.trigram.keys()),
                              madison.trigram), "\n")

    test.main(test_essays, hamilton.unigram, hamilton.bigram, hamilton.trigram,
              madison.unigram, madison.bigram, madison.trigram)
Пример #19
0
def test():

    import test

    print('Starting Testing')
    test.main()
Пример #20
0
 def run():
     if args.English:
         test.main("en")
     elif args.Hindi:
         test.main("hi")
     elif args.Spanish:
         test.main("es")
     elif args.French:
         test.main("fr")
     elif args.Arabic:
         test.main("ar")
     elif args.Bengali:
         test.main("bn")
     elif args.Russian:
         test.main("ru")
     elif args.Portuguese:
         test.main("pt")
     elif args.Indonesian:
         test.main("id")
     else:
         test.main("en")
Пример #21
0
                        type=float,
                        default=0.0005,
                        help='L2 Reg rate')
    parser.add_argument('--batch', type=int, default=32, help='batch size')
    parser.add_argument('--epoch',
                        type=int,
                        default=500,
                        help='number of epochs to train')
    parser.add_argument('--no-shuffle',
                        action='store_true',
                        default=False,
                        help='don\'t shuffle training data')
    """ test options """
    parser.add_argument('--load_model', default=None, help='path to model')
    parser.add_argument('--load_word', default=None, help='path to words')
    parser.add_argument('--load_label', default=None, help='path to labels')
    parser.add_argument('--load_emb', default=None, help='path to embs')

    argv = parser.parse_args()

    print
    print argv
    print

    if argv.mode == 'train':
        import train
        train.main(argv)
    else:
        import test
        test.main(argv)
Пример #22
0
def main(opt):
    os.makedirs('weights', exist_ok=True)

    # Configure run
    data_config = parse_data_config(opt.data_config_path)
    num_classes = int(data_config['classes'])
    if platform == 'darwin':  # MacOS (local)
        train_path = data_config['train']
    else:  # linux (cloud, i.e. gcp)
        train_path = '../coco/trainvalno5k.part'

    # Initialize model
    model = Darknet(opt.cfg, opt.img_size)

    # Get dataloader
    dataloader = load_images_and_labels(train_path,
                                        batch_size=opt.batch_size,
                                        img_size=opt.img_size,
                                        augment=True)

    # Reload saved optimizer state
    start_epoch = 0
    best_loss = float('inf')
    if opt.resume:
        checkpoint = torch.load('weights/latest.pt', map_location='cpu')

        model.load_state_dict(checkpoint['model'])
        if torch.cuda.device_count() > 1:
            print('Using ', torch.cuda.device_count(), ' GPUs')
            model = nn.DataParallel(model)
        model.to(device).train()

        # # Transfer learning (train only YOLO layers)
        # for i, (name, p) in enumerate(model.named_parameters()):
        #     if p.shape[0] != 650:  # not YOLO layer
        #         p.requires_grad = False

        # Set optimizer
        if opt.optimizer is 'Adam':
            optimizer = torch.optim.Adam(filter(lambda p: p.requires_grad,
                                                model.parameters()),
                                         lr=1e-4,
                                         weight_decay=5e-4)
        else:
            optimizer = torch.optim.SGD(filter(lambda p: p.requires_grad,
                                               model.parameters()),
                                        lr=1e-3,
                                        momentum=.9,
                                        weight_decay=5e-4)

        start_epoch = checkpoint['epoch'] + 1
        if checkpoint['optimizer'] is not None:
            optimizer.load_state_dict(checkpoint['optimizer'])
            best_loss = checkpoint['best_loss']

        del checkpoint  # current, saved

    else:
        # Initialize model with darknet53 weights (optional)
        if not os.path.isfile('weights/darknet53.conv.74'):
            os.system(
                'wget https://pjreddie.com/media/files/darknet53.conv.74 -P weights'
            )
        load_weights(model, 'weights/darknet53.conv.74')

        if torch.cuda.device_count() > 1:
            print('Using ', torch.cuda.device_count(), ' GPUs')
            model = nn.DataParallel(model)
        model.to(device).train()

        # Set optimizer
        if opt.optimizer is 'Adam':
            optimizer = torch.optim.Adam(filter(lambda p: p.requires_grad,
                                                model.parameters()),
                                         lr=1e-4,
                                         weight_decay=5e-4)
        else:
            optimizer = torch.optim.SGD(filter(lambda p: p.requires_grad,
                                               model.parameters()),
                                        lr=1e-3,
                                        momentum=.9,
                                        weight_decay=5e-4)

    # Set scheduler
    # scheduler = torch.optim.lr_scheduler.MultiStepLR(optimizer, milestones=[54, 61], gamma=0.1)

    model_info(model)
    t0, t1 = time.time(), time.time()
    mean_recall, mean_precision = 0, 0
    print('%11s' * 16 %
          ('Epoch', 'Batch', 'x', 'y', 'w', 'h', 'conf', 'cls', 'total', 'P',
           'R', 'nTargets', 'TP', 'FP', 'FN', 'time'))
    for epoch in range(opt.epochs):
        epoch += start_epoch

        # Update scheduler (automatic)
        # scheduler.step()

        # Update scheduler (manual)  at 0, 54, 61 epochs to 1e-3, 1e-4, 1e-5
        if epoch > 50:
            lr = 1e-4
        else:
            lr = 1e-3
        for g in optimizer.param_groups:
            g['lr'] = lr

        ui = -1
        rloss = defaultdict(float)  # running loss
        metrics = torch.zeros(3, num_classes)
        optimizer.zero_grad()
        for i, (imgs, targets) in enumerate(dataloader):
            if sum([len(x) for x in targets]) < 1:  # if no targets continue
                continue

            # SGD burn-in
            if (epoch == 0) & (i <= 1000):
                lr = 1e-3 * (i / 1000)**4
                for g in optimizer.param_groups:
                    g['lr'] = lr

            # Compute loss, compute gradient, update parameters
            loss = model(imgs.to(device),
                         targets,
                         batch_report=opt.batch_report)
            loss.backward()

            # accumulated_batches = 1  # accumulate gradient for 4 batches before stepping optimizer
            # if ((i+1) % accumulated_batches == 0) or (i == len(dataloader) - 1):
            optimizer.step()
            optimizer.zero_grad()

            # Running epoch-means of tracked metrics
            ui += 1
            for key, val in model.losses.items():
                rloss[key] = (rloss[key] * ui + val) / (ui + 1)

            if opt.batch_report:
                TP, FP, FN = metrics
                metrics += model.losses['metrics']

                # Precision
                precision = TP / (TP + FP)
                k = (TP + FP) > 0
                if k.sum() > 0:
                    mean_precision = precision[k].mean()

                # Recall
                recall = TP / (TP + FN)
                k = (TP + FN) > 0
                if k.sum() > 0:
                    mean_recall = recall[k].mean()

            s = ('%11s%11s' + '%11.3g' * 14) % (
                '%g/%g' % (epoch, opt.epochs - 1), '%g/%g' %
                (i, len(dataloader) - 1), rloss['x'], rloss['y'], rloss['w'],
                rloss['h'], rloss['conf'], rloss['cls'], rloss['loss'],
                mean_precision, mean_recall, model.losses['nT'],
                model.losses['TP'], model.losses['FP'], model.losses['FN'],
                time.time() - t1)
            t1 = time.time()
            print(s)

        # Update best loss
        loss_per_target = rloss['loss'] / rloss['nT']
        if loss_per_target < best_loss:
            best_loss = loss_per_target

        # Save latest checkpoint
        checkpoint = {
            'epoch': epoch,
            'best_loss': best_loss,
            'model': model.state_dict(),
            'optimizer': optimizer.state_dict()
        }
        torch.save(checkpoint, 'weights/latest.pt')

        # Save best checkpoint
        if best_loss == loss_per_target:
            os.system('cp weights/latest.pt weights/best.pt')

        # Save backup weights every 5 epochs
        if (epoch > 0) & (epoch % 5 == 0):
            os.system('cp weights/latest.pt weights/backup' + str(epoch) +
                      '.pt')

        # Calculate mAP
        test.opt.weights_path = 'weights/latest.pt'
        mAP, R, P = test.main(test.opt)

        # Write epoch results
        with open('results.txt', 'a') as file:
            file.write(s + '%11.3g' * 3 % (mAP, P, R) + '\n')

    # Save final model
    dt = time.time() - t0
    print('Finished %g epochs in %.2fs (%.2fs/epoch)' % (epoch, dt, dt /
                                                         (epoch + 1)))
Пример #23
0
def evaluate(sb, options):
    state = EvalState()
    phase_argv = ['--sandbox', sb.get_root()]
    with ioutil.WorkingDir(sb.get_root()) as td:
        with sb.lock('eval') as lock:
            try:
                try:
                    if not options.no_update:
                        with Phase(state, EvalPhase.UPDATE, lock) as phase:
                            state.err = update(sb, lock)
                    if not state.err:
                        with Phase(state, EvalPhase.BUILD, lock) as phase:
                            argv = get_build_phase_args(phase_argv, options)
                            state.err = build.main(argv)
                    if not state.err:
                        with Phase(state, EvalPhase.TEST, lock) as phase:
                            argv = get_test_phase_args(["test"], options)
                            state.err = test.main(argv)
                    if (not state.err) and sb.get_sandboxtype().get_should_publish():
                        with Phase(state, EvalPhase.PUBLISH, lock) as phase:
                            state.err = publish.main(phase_argv)
                except:
                    txt = traceback.format_exc()
                    print(txt)
                    # It is possible for us to get an exception as we try to enter
                    # a phase (including the first one). In such a case, we need
                    # to work extra hard to help the user understand what's wrong.
                    txt = txt.replace('\r', '').replace('\n', '; ').replace(',', ' ')
                    state.reason = 'exception in build process itself: ' + txt
                    if not state.timestamps:
                        state.timestamps.append(time.time())
                        state.phase = EvalPhase.UPDATE
            finally:
                if os.path.exists(os.path.join(sb.get_root(), 'notify.txt')):
                    if (not sb.get_sandboxtype().get_notify_on_success()) and (not state.err):
                        os.remove('%snotify.txt' % sb.get_root())
                    else:
                        notify = open('%snotify.txt' % sb.get_root(), 'r')
                        emails = notify.read()
                        notify.close()
                        body = ''
                        if os.path.exists(os.path.join(sb.get_root(), 'eval-log.txt')):
                            body = os.path.join(sb.get_root(), 'eval-log.txt')
                        os.remove('%snotify.txt' % sb.get_root())
                        bi = buildinfo.BuildInfo()
                        if state.err:
                            status = 'Failed'
                        else:
                            status = 'Succeeded'
                        subject = '%s build of %s on %s %s.' % (sb.get_variant(), sb.get_top_component(), bi.host, status)
                        arguments = '--to %s --sender sadm --subject "%s" --host smtp.example.com --port 587' % (emails, subject) # TODO KIM TO CONF
                        arguments += ' --username [email protected] --password password' # TODO KIM TO CONF
                        if body:
                            arguments += ' --body "%s"' % body
                        os.system('python %s/buildscripts/mailout.py %s' % (sb.get_code_root(), arguments))
                if not state.err:
                    state.reason = ''
                if _should_report(sb, options):
                    report(sb, state)
                else:
                    print('Skipping report phase.')
    return state.err
Пример #24
0
    parser.add_argument('--init_emb', default=None, help='Initial embedding to be loaded')
    parser.add_argument('--opt', default='adam', help='optimization method')
    parser.add_argument('--lr', type=float, default=0.01, help='learning rate')
    parser.add_argument('--reg', type=float, default=0.0001, help='L2 Reg rate')
    parser.add_argument('--batch', type=int, default=32, help='batch size')
    parser.add_argument('--epoch', type=int, default=500, help='number of epochs to train')
    parser.add_argument('--no-shuffle', action='store_true', default=False, help='don\'t shuffle training data')

    """ test options """
    parser.add_argument('--model', default=None, help='path to model')
    parser.add_argument('--arg_dict', default=None, help='path to arg dict')
    parser.add_argument('--vocab_dict', default=None, help='path to vocab dict')
    parser.add_argument('--emb_dict', default=None, help='path to emb dict')

    argv = parser.parse_args()

    print
    print argv
    print

    if argv.mode == 'train':
        import train
        train.main(argv)
    else:
        import test
        assert argv.model is not None
        assert argv.arg_dict is not None
        assert argv.vocab_dict is not None
        assert argv.emb_dict is not None
        test.main(argv)
__author__ = 'EL13115'
import Tkinter
import tkFileDialog

import test

root = Tkinter.Tk()
filename = tkFileDialog.askopenfilename(parent=root, title='Choose a file')
help_class = test.main_args()
if filename != None:
    help_class.url = filename
    test.main(help_class)
else:
    test.main(help_class)

root.mainloop()
Пример #26
0
    'Intended Audience :: Developers',
    'Intended Audience :: Information Technology',
    'License :: OSI Approved :: BSD License',
    'Programming Language :: Cython',
    'Programming Language :: Python :: 2',
    'Programming Language :: Python :: 2.3',
    'Programming Language :: Python :: 2.4',
    'Programming Language :: Python :: 2.5',
    'Programming Language :: Python :: 2.6',
    'Programming Language :: Python :: 3',
    'Programming Language :: Python :: 3.0',
    'Programming Language :: C',
    'Operating System :: OS Independent',
    'Topic :: Text Processing :: Markup :: HTML',
    'Topic :: Text Processing :: Markup :: XML',
    'Topic :: Software Development :: Libraries :: Python Modules'
    ],

    package_dir = {'': 'src'},
    packages = ['lxml', 'lxml.html'],
    ext_modules = setupinfo.ext_modules(
        STATIC_INCLUDE_DIRS, STATIC_LIBRARY_DIRS,
        STATIC_CFLAGS, STATIC_BINARIES),
    **extra_options
)

if OPTION_RUN_TESTS:
    print("Running tests.")
    import test
    sys.exit( test.main(sys.argv[:1]) )
Пример #27
0
Файл: ui.py Проект: BambooL/pbe
def generate():
	test.parsedata(T.get())
	prog_list = test.main()
	output = sorted(list(prog_list), key=len)
	T2.insert(END, output[0])
Пример #28
0
    return yesterday_round


current_round = utils.get_current_round()

yesterday_round = get_yesterdays_round()

if str(current_round) == str(yesterday_round):

    print(datetime.now())

    print('--Still the same round as yesterday--')

    print('--No code called for today--', end="\n\n")

else:

    print(datetime.now())

    save_current_round(current_round)

    print("--Round changed from {} to {}--".format(yesterday_round,
                                                   current_round))

    main.main(current_round, yesterday_round)

    print("--main.main() Called--")

    print('--Current round saved--', end="\n\n")
Пример #29
0
 def test_settings_error(self, sys_exit):
     # When the settings file cannot be imported the test runner
     # wil exit with a message and a specific exit code.
     test.main('cheeseshop.tilsit', 'stilton')
     self.assertEqual(sys_exit.call_args, ((1,), {}))
Пример #30
0
def main():
    """TODO: Docstring for main.
    :returns: TODO

    """
    test.main()
Пример #31
0
                        output_dir + '/%s-%s' % (test, plot_file),
                        )


if __name__ == "__main__":
    
    parser = OptionParser()
    parser.add_option('-b', '--BuildName', default=None)
    (options, args) = parser.parse_args()

    print "Are you sure you want to rerun the entire test suite? (y/n)"
    print "You will create a lot of images and it may take a while"
    res = raw_input()
    if res == 'y':
        print "RUNNING ALL TEST CASES AND SAVING IT"
        test.main(options.BuildName) 
        dir_name = make_dir_name()
        if not os.path.exists(dir_name):
            os.mkdir(dir_name)
        print 'Copying data to ' + dir_name
        shutil.copy('test_results/test_event_results.html', dir_name)
        shutil.copy('test_results/test_event_results.csv', dir_name)
        shutil.copy('test_results/test_frame_results.html', dir_name)
        shutil.copy('test_results/test_frame_results.csv', dir_name)


        # so that it renders in github
        shutil.copy('test_results/test_event_results_bw.html', dir_name + '/' + 'README.md')
        shutil.copy('test_results/test_frame_results_bw.html', dir_name + '/' + 'README.md')
        copy_test_plots('test_suite/test_cases/', dir_name)
        
Пример #32
0
#!/usr/bin/env python
# -*- coding: UTF-8 -*-

#
# Copyright 2016 sadikovi
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

import sys
import test
sys.exit(test.main())
Пример #33
0
        invalidButNotRejected = '%:$|!#$%#$U%O\\/^'
        lock, _ = self.testConstructor(filename=invalidButNotRejected)
        self.assertEqual(invalidButNotRejected, lock.filename)


    def test_obtain_AND_release(self):
        lock, filename = self.testConstructor()
        self.failUnless(lock.obtain())
        self.failUnless(os.path.exists(lock.filename))
        lock.release()
        self.failIf(os.path.exists(lock.filename))


    def test_release_invalid(self):
        # Make sure the FSLock doesn't segfault if the lock file gets deleted
        # out from under it.  It's allowed to raise an exception, though.
        lock, filename = self.testConstructor()
        self.failUnless(lock.obtain())
        self.failUnless(os.path.exists(lock.filename))
        os.remove(lock.filename)
        try:
            lock.release()
        except:
            pass


if __name__ == '__main__':
    import test
    test.main(suite=getFullTestSuite())
Пример #34
0
def main():
    # constants
    num_channels = cfg.config['num_channels']
    classes = cfg.config['classes']
    num_classes = len(classes)
    height = cfg.config['height']
    width = cfg.config['width']
    anchors = cfg.config['anchors']
    num_anchors = len(anchors[0])
    nms_iou = cfg.config['NMS_IoU']
    confidency = cfg.config['confidency']
    cuda = cfg.config['CUDA']
    weight_path = cfg.config['path']['detect_weight']

    # unloaded net
    net = None

    # main loop
    while True:
        # print usage
        # print('Available commands:')
        # print('  detect image_path output_path')
        # print('  train')
        # print('  test')
        # print('  quit | q | exit')
        print('The Detector is Ready.')

        # get user input
        with open('pipe', 'r') as pipe:
            command = pipe.read().replace('\n', '')

        # condition to quit
        if command == 'q':
            break
        elif command == 'quit':
            break
        elif command == 'exit':
            break

        command = command.split(' ')

        # detect
        if command[0] == 'detect':
            if len(command) != 3:
                print('usage: detect image_path output_path')
            else:
                image_path = command[1]
                output_path = command[2]

                # load net if it is not loaded
                if net is None:
                    net = model.YOLOv3(num_channels, num_classes, num_anchors)
                    if cuda:
                        net = net.cuda()
                    net.load_state_dict(torch.load(weight_path))
                    print('Load weight from {}'.format(weight_path))

                # load image
                image = pre.load_image(image_path, height, width, cuda)

                # predict and write bbox
                prediction = detect.detect(net, image, anchors, confidency,
                                           nms_iou, cuda)
                detect.write_prediction(prediction, output_path, height, width)

        # train
        elif command[0] == 'train':
            if len(command) != 1:
                print('usage: train')
            train.main()

        # test
        elif command[0] == 'test':
            if len(command) != 1:
                print('usage: test')
            test.main()

        # show usage
        else:
            print('{}: Unknown command.'.format(command))
Пример #35
0
 def run(self):
     self.run_command('build')
     import test
     test.main()
Пример #36
0
#!/usr/bin/env python
#_*_coding:utf-8_*_
# 测试模块调用
# 直接使用脚本名调用即可
# 会生成 .pyc文件
import test

test.main("aaaa")
def main(argv):
    arg_parser = argparse.ArgumentParser(
        description='Update the Python Project Template using diff3.')
    arg_parser.add_argument(
        'current_project_directory',
        help='Directory for the project wanting to be updated')
    # arg_parser.add_argument(
    #     'old_ppt_directory',
    #     help='PPT version from which this project originated')
    # arg_parser.add_argument(
    #     'new_ppt_directory',
    #     help='PPT version to which this project should be updated')

    args = arg_parser.parse_args(args=argv[1:])

    # Find the .ppt-version file and read the commit hash from it.
    ppt_version_path = os.path.join(
        args.current_project_directory, '.ppt-version')
    if not os.path.exists(ppt_version_path):
        raise SystemExit(
            'PPT version cookie not found: {0}'.format(ppt_version_path))
    with open(ppt_version_path) as ppt_version_file:
        for line in ppt_version_file:
            # Allow for comments in the file.
            if not line.startswith('#'):
                old_revision = line.rstrip()
                break

    # Grab the path to metadata from setup.py, as we know where that file is.
    # We're not sure of the directory where metadata.py resides. We need to
    # change directories instead of importing the module directly because there
    # are dependent imports.
    print("Finding project's `metadata.py' file...")
    with cwd(args.current_project_directory):
        current_project_setup_module = imp.load_source(
            'setup', os.path.join(args.current_project_directory, 'setup.py'))
    package_name = current_project_setup_module.metadata.package
    metadata_path = os.path.join(
        args.current_project_directory, package_name, 'metadata.py')
    if not os.path.exists(metadata_path):
        raise SystemExit(
            'Project metadata file not found: {0}'.format(metadata_path))

    # Setup the new PPT directory.
    print('Setting up new PPT directory...')
    new_ppt_directory = mkdtemp(prefix='ppt-new-')
    test.main(['unused_progname',
               '--metadata-path', metadata_path,
               new_ppt_directory])

    # Setup the old PPT directory.
    print('Setting up old PPT directory...')
    old_ppt_directory = mkdtemp(prefix='ppt-old-')
    test.main(['unused_progname',
               '--metadata-path', metadata_path,
               '--revision', old_revision,
               old_ppt_directory])

    dirs = [
        args.current_project_directory,
        old_ppt_directory,
        new_ppt_directory,
    ]

    with cwd(args.current_project_directory):
        git_ls_files = subprocess.check_output(
            ['git', 'ls-files']).splitlines()

    # Don't diff3 the version cookie.
    git_ls_files.remove('.ppt-version')

    print('Running diff3...')
    for git_path in git_ls_files:
        paths = []
        for dir_ in dirs:
            path = os.path.join(dir_, git_path)
            if not os.path.exists(path):
                path = '/dev/null'
            paths.append(path)
        process = subprocess.Popen(
            ['diff3', '--merge'] + paths,
            stdout=subprocess.PIPE)
        diff3_out, diff3_err = process.communicate()
        if process.returncode != 0:
            print('{0}: merge conflicts found, please resolve manually'.format(
                paths[0]))
        with open(paths[0], 'w') as current_file:
            current_file.write(diff3_out)

    new_revision = subprocess.check_output(
        ['git', 'rev-parse', 'HEAD']).rstrip()
    print('Updating PPT version cookie (revision {0})...'.format(new_revision))
    # Open file for reading and writing.
    with open(ppt_version_path, 'r+') as ppt_version_file:
        # Strip off the last line.
        new_contents_lines = ppt_version_file.readlines()[:-1]
        # Append the new revision.
        new_contents_lines.append(new_revision)
        # Write new contents to file.
        new_contents = ''.join(new_contents_lines)
        ppt_version_file.seek(0)
        print(new_contents, file=ppt_version_file)

    print('Removing temporary directories...')
    for dir_ in [old_ppt_directory, new_ppt_directory]:
        shutil.rmtree(dir_)
Пример #38
0
def main(expdir, recipe, computing):
    '''main function'''

    if not os.path.isdir(expdir):
        raise Exception('Could not find expdir %s' % expdir)

    #read the testing config file
    testconf = ConfigParser()
    testconf.read(os.path.join(recipe, 'test.cfg'))

    #read the data config file
    if not os.path.exists(os.path.join(recipe, 'database.cfg')):
        raise Exception('cannot find database.cfg in %s' % recipe)

    dataconf = ConfigParser()
    dataconf.read(os.path.join(recipe, 'database.cfg'))

    if os.path.exists(os.path.join(recipe, 'testfeats')):
        shutil.copyfile(os.path.join(recipe, 'testfeats'),
                        os.path.join(expdir, 'testfeats'))
        shutil.copyfile(os.path.join(recipe, 'testtasks'),
                        os.path.join(expdir, 'testtasks'))
    elif os.path.exists(os.path.join(expdir, 'testfeats')):
        print('exists')
    else:
        #create the training files
        fid = open(os.path.join(expdir, 'testfeats'), 'w')
        tid = open(os.path.join(expdir, 'testtasks'), 'w')

        for s in testconf.get('test', 'datasections').split(' '):
            with open(os.path.join(dataconf.get(s, 'features'), 'feats')) as f:
                lines = f.readlines()
                lines = [s + '_' + line for line in lines]
                fid.writelines(lines)
            with open(dataconf.get(s, 'tasks')) as f:
                lines = f.readlines()
                lines = [s + '_' + line for line in lines]
                tid.writelines(lines)

        fid.close()
        tid.close()

    if computing in ('condor', 'condor_gpu'):
        #create the outputs directory
        if not os.path.isdir(os.path.join(expdir, 'outputs')):
            os.makedirs(os.path.join(expdir, 'outputs'))

        if computing == 'condor_gpu':
            jobfile = 'run_script_GPU.job'
        else:
            jobfile = 'run_script.job'

        #only submit the job if it not running yet
        in_queue = os.popen('if condor_q -nobatch -wide | grep -q %s; '
                            'then echo true; else echo false; fi' %
                            expdir).read().strip() == 'true'

        #submit the condor job
        if not in_queue:
            os.system('condor_submit expdir=%s script=test'
                      ' assist/condor/%s' % (expdir, jobfile))
    else:
        test.main(expdir)
def main(argv):
    arg_parser = argparse.ArgumentParser(
        description='Update the Python Project Template using diff3.')
    arg_parser.add_argument(
        'current_project_directory',
        help='Directory for the project wanting to be updated')
    # arg_parser.add_argument(
    #     'old_ppt_directory',
    #     help='PPT version from which this project originated')
    # arg_parser.add_argument(
    #     'new_ppt_directory',
    #     help='PPT version to which this project should be updated')

    args = arg_parser.parse_args(args=argv[1:])
    # Grab the path to metadata from setup.py, as we know where that file is.
    old_revision, ppt_version_path = handle_git_ppt_version(args)
    # We're not sure of the directory where metadata.py resides. We need to
    # change directories instead of importing the module directly because there
    # are dependent imports.
    print("Finding project's `metadata.py' file...")
    with cwd(args.current_project_directory):
        current_project_setup_module = imp.load_source(
            'setup', os.path.join(args.current_project_directory, 'setup.py'))
    package_name = current_project_setup_module.metadata.package
    metadata_path = os.path.join(args.current_project_directory, package_name,
                                 'metadata.py')
    if not os.path.exists(metadata_path):
        raise SystemExit(
            'Project metadata file not found: {0}'.format(metadata_path))

    # Setup the new PPT directory.
    print('Setting up new PPT directory...')
    new_ppt_directory = mkdtemp(prefix='ppt-new-')
    test.main([
        'unused_progname', '--metadata-path', metadata_path, new_ppt_directory
    ])

    # Setup the old PPT directory.
    print('Setting up old PPT directory...')
    old_ppt_directory = mkdtemp(prefix='ppt-old-')
    test.main([
        'unused_progname', '--metadata-path', metadata_path, '--revision',
        old_revision, old_ppt_directory
    ])

    dirs = [
        args.current_project_directory,
        old_ppt_directory,
        new_ppt_directory,
    ]

    with cwd(args.current_project_directory):
        git_ls_files = subprocess.check_output(['git',
                                                'ls-files']).splitlines()

    # Don't diff3 the version cookie.
    git_ls_files.remove('.ppt-version')

    print('Running diff3...')
    for git_path in git_ls_files:
        paths = []
        for dir_ in dirs:
            path = os.path.join(dir_, git_path)
            if not os.path.exists(path):
                path = '/dev/null'
            paths.append(path)
        process = subprocess.Popen(['diff3', '--merge'] + paths,
                                   stdout=subprocess.PIPE)
        diff3_out, diff3_err = process.communicate()
        if process.returncode != 0:
            print('{0}: merge conflicts found, please resolve manually'.format(
                paths[0]))
        with open(paths[0], 'w') as current_file:
            current_file.write(diff3_out)

    new_revision = subprocess.check_output(['git', 'rev-parse',
                                            'HEAD']).rstrip()
    print('Updating PPT version cookie (revision {0})...'.format(new_revision))
    # Open file for reading and writing.
    with open(ppt_version_path, 'r+') as ppt_version_file:
        # Strip off the last line.
        new_contents_lines = ppt_version_file.readlines()[:-1]
        # Append the new revision.
        new_contents_lines.append(new_revision)
        # Write new contents to file.
        new_contents = ''.join(new_contents_lines)
        ppt_version_file.seek(0)
        print(new_contents, file=ppt_version_file)

    print('Removing temporary directories...')
    for dir_ in [old_ppt_directory, new_ppt_directory]:
        shutil.rmtree(dir_)
Пример #40
0
def test():
    import test
    test.main()
def runtest():
    '''
    Runs the test.py.
    '''
    from test import main
    main()
Пример #42
0
def main():
    py.init()
    continuer = 1
    son = py.mixer.Sound("enclume.wav")

    fenetre = py.display.set_mode((1200, 700))
    fond = py.image.load("background1.jpg").convert()

    perso = py.image.load("rund.png").convert_alpha()
    persog = py.image.load("rung.png").convert_alpha()
    enfantok = py.image.load("ice_bucket1.png").convert_alpha()
    enfantmouille = py.image.load("ice_bucket4.png").convert_alpha()

    py.font.init()  #initialisation du texte de fond
    font = py.font.Font(None, 36)
    text = font.render("Ice Bucket Challenge 2014", 1, (0, 0, 0))
    fond.blit(text, (10, 10))

    position_enfants = [(random.randint(0, 1110), random.randint(0, 570)),
                        (random.randint(0, 1110), random.randint(0, 570)),
                        (random.randint(0, 1110), random.randint(0, 570)),
                        (random.randint(0, 1110), random.randint(0, 570)),
                        (random.randint(0, 1110), random.randint(0, 570)),
                        (random.randint(0, 1110), random.randint(0, 570)),
                        (random.randint(0, 1110), random.randint(0, 570))]
    renverse = np.ones(7)
    perso_x = 0
    perso_y = 0
    droite = True

    fenetre.blit(fond, (0, 0))
    fenetre.blit(perso, (perso_x, perso_y))
    py.display.flip()
    count = 0
    py.key.set_repeat(20, 1)
    lastfalse = random.randint(0, 6)
    renverse[lastfalse] = 0
    pasttime = py.time.get_ticks()

    while continuer and count < 10:
        if (py.time.get_ticks() - pasttime) >= 700:
            pasttime = py.time.get_ticks()
            renverse[lastfalse] = 1
            lastfalse = random.randint(0, 6)
            renverse[lastfalse] = 0

        for event in py.event.get(
        ):  #On parcours la liste de tous les événements reçus
            if (event.type == QUIT):  #Si un de ces événements est de type QUI
                continuer = 0
            if event.type == MOUSEMOTION:
                perso_x = event.pos[0] - 20
                perso_y = event.pos[1] - 20

    #        if event.type == KEYDOWN:       #fait bouger le personnage à droite ou à gauche
    #            if event.key == K_RIGHT:
    #                perso_x=perso_x+2
    #                droite=True
    #            if event.key == K_LEFT:
    #                perso_x=perso_x-2
    #                droite=False
    #            if event.key == K_UP:
    #                perso_y=perso_y-2
    #            if event.key == K_DOWN:
    #                perso_y=perso_y+2
            if event.type == MOUSEBUTTONDOWN:
                if event.button == 1:
                    if (perso_x > position_enfants[lastfalse][0] - 90
                            and perso_x < position_enfants[lastfalse][0] + 83
                            and perso_y < position_enfants[lastfalse][1] + 100
                            and
                            perso_y > position_enfants[lastfalse][1] - 127):
                        count += 1
                        son.play()
                        position_enfants[lastfalse] = (random.randint(0, 1110),
                                                       random.randint(0, 570))
        fenetre.blit(fond, (0, 0))

        for i in range(0, 6):
            if (renverse[i]):
                fenetre.blit(enfantok, position_enfants[i])
            else:
                fenetre.blit(enfantmouille, position_enfants[i])
        if droite:
            fenetre.blit(perso, ((perso_x, perso_y)))
        else:
            fenetre.blit(persog, ((perso_x, perso_y)))
        py.display.flip()
    fenetre = py.display.set_mode((693, 623))
    thefloor = py.image.load("floor_is.jpg").convert()
    fenetre.blit(thefloor, (0, 0))
    py.mixer.init()  #initialisation de la musique
    py.mixer.music.load("grrr.wav")
    py.mixer.music.play()
    py.display.flip()
    time.sleep(4)
    test.main()
Пример #43
0
def 輸入檔案並測驗():
    filename = tkFileDialog.askopenfilename()
    print(filename)
    狀況欄["text"]= "我覺得這是" + test.main(filename)
Пример #44
0
        self.tok('0', [(0,1,'<NUM>','0')])
        self.tok('0.', [(0,1,'<NUM>','0')])
        self.tok('-1', [(0,2,'<NUM>','-1')])
        self.tok('+1', [(1,2,'<NUM>','1')])
        self.tok('+12.', [(1,3,'<NUM>','12')])
        self.tok('-12.', [(0,3,'<NUM>','-12')])
        self.tok('+.1', [(1,3,'<NUM>','.1')])
        self.tok('+.1.', [(1,3,'<NUM>','.1')])
        self.tok('-.1', [(0,3,'<NUM>','-.1')])
        self.tok('-.1.', [(0,3,'<NUM>','-.1')])
        self.tok('-1.5abc', [(0,4,'<NUM>','-1.5'), (4,7,'<ALPHANUM>','abc')])
        self.tok('-123.4567-abc', [(0,9,'<NUM>','-123.4567'), (10,13,'<ALPHANUM>','abc')])


### SUPPORT ###
def _nameOfTestFile():
    # Can't naively use __file__ because it changes from 'test_analysis.py'
    # to 'test_analysis.py[c|o]' upon bytecode compilation, and the bytecode
    # file isn't suitable for [ASCII-oriented] tokenization.
    return test_base.getFilenameOfThisPythonTestModule(__file__)


def _textOfTestFile():
    return file(_nameOfTestFile(), 'rb').read()


if __name__ == '__main__':
    import test
    test.main(suite=getFullTestSuite(), createTestIndex=False)
Пример #45
0
def evaluate(sb, options):
    state = EvalState()
    phase_argv = ['--sandbox', sb.get_root()]
    with ioutil.WorkingDir(sb.get_root()) as td:
        with sb.lock('eval') as lock:
            try:
                try:
                    if not options.no_update:
                        with Phase(state, EvalPhase.UPDATE, lock) as phase:
                            state.err = update(sb, lock)
                    if not state.err:
                        with Phase(state, EvalPhase.BUILD, lock) as phase:
                            argv = get_build_phase_args(phase_argv, options)
                            state.err = build.main(argv)
                    if not state.err:
                        with Phase(state, EvalPhase.TEST, lock) as phase:
                            argv = get_test_phase_args(["test"], options)
                            state.err = test.main(argv)
                    if (not state.err
                        ) and sb.get_sandboxtype().get_should_publish():
                        with Phase(state, EvalPhase.PUBLISH, lock) as phase:
                            state.err = publish.main(phase_argv)
                except:
                    txt = traceback.format_exc()
                    print(txt)
                    # It is possible for us to get an exception as we try to enter
                    # a phase (including the first one). In such a case, we need
                    # to work extra hard to help the user understand what's wrong.
                    txt = txt.replace('\r',
                                      '').replace('\n',
                                                  '; ').replace(',', ' ')
                    state.reason = 'exception in build process itself: ' + txt
                    if not state.timestamps:
                        state.timestamps.append(time.time())
                        state.phase = EvalPhase.UPDATE
            finally:
                if os.path.exists(os.path.join(sb.get_root(), 'notify.txt')):
                    if (not sb.get_sandboxtype().get_notify_on_success()) and (
                            not state.err):
                        os.remove('%snotify.txt' % sb.get_root())
                    else:
                        notify = open('%snotify.txt' % sb.get_root(), 'r')
                        emails = notify.read()
                        notify.close()
                        body = ''
                        if os.path.exists(
                                os.path.join(sb.get_root(), 'eval-log.txt')):
                            body = os.path.join(sb.get_root(), 'eval-log.txt')
                        os.remove('%snotify.txt' % sb.get_root())
                        bi = buildinfo.BuildInfo()
                        if state.err:
                            status = 'Failed'
                        else:
                            status = 'Succeeded'
                        subject = '%s build of %s on %s %s.' % (sb.get_variant(
                        ), sb.get_top_component(), bi.host, status)
                        arguments = '--to %s --sender sadm --subject "%s" --host smtp.example.com --port 587' % (
                            emails, subject)  # TODO KIM TO CONF
                        arguments += ' --username [email protected] --password password'  # TODO KIM TO CONF
                        if body:
                            arguments += ' --body "%s"' % body
                        os.system('python %s/buildscripts/mailout.py %s' %
                                  (sb.get_code_root(), arguments))
                if not state.err:
                    state.reason = ''
                if _should_report(sb, options):
                    report(sb, state)
                else:
                    print('Skipping report phase.')
    return state.err
Пример #46
0
np.random.seed(params['seed'])
random.seed(params['seed'])
lasagne.random.set_rng(np.random)

# save directory
w2v_filename = params['word2vec'].split('/')[-1].split(
    '.')[0] if params['word2vec'] else 'None'
save_path = ('experiments/' + params['model'] + '/' +
             params['dataset'].split('/')[0] +
             '/reg%s' % params['regularizer'] + '%.3f' % params['lambda'] +
             '_nhid%d' % params['nhidden'] + '_nlayers%d' % params['nlayers'] +
             '_dropout%.1f' % params['dropout'] + '_%s' % w2v_filename +
             '_chardim%d' % params['char_dim'] +
             '_train%d' % params['train_emb'] +
             '_subsample%d' % params['subsample'] +
             '_seed%d' % params['seed'] + '_use-feat%d' % params['use_feat'] +
             '_traincut%.1f' % params['train_cut'] +
             '_gf%s' % params['gating_fn'] + '{}/'.format(NAME))
if not os.path.exists(save_path): os.makedirs(save_path)

# train
if params['mode'] < 2:
    train.main(save_path, params)

# test
if params['mode'] == 0 or params['mode'] == 2:
    test.main(save_path, params)
elif params['mode'] == 3:
    test.main(save_path, params, mode='validation')
Пример #47
0
import os
from test import main
import numpy as np
import subprocess

mac_f1_list = []
mic_f1_list = []
NMI_list = []
ARI_list = []
os.environ['MKL_THREADING_LAYER'] = 'GNU'
seeds = [228, 7243, 3295, 4020, 8149, 4832, 741, 6538, 7850, 6391]

for i in seeds:
    p = subprocess.Popen("python main.py --seed {}".format(i), shell=True)
    p.wait()
    p.kill()
    macro_f1_mean, micro_f1_mean, NMI, ARI = main()
    mac_f1_list.append(macro_f1_mean)
    mic_f1_list.append(micro_f1_mean)
    NMI_list.append(NMI)
    ARI_list.append(ARI)
print(
    '\n************************** Average results *******************************'
)
print('Macro-F1: {:.4f}, {:.4f}, {:.4f}, {:.4f}'.format(
    *np.mean(np.array(mac_f1_list), axis=0).tolist()))
print('Micro-F1: {:.4f}, {:.4f}, {:.4f}, {:.4f}'.format(
    *np.mean(np.array(mic_f1_list), axis=0).tolist()))
print('NMI: {:.4f}, ARI: {:.4f}'.format(np.mean(NMI_list), np.mean(ARI_list)))
Пример #48
0
an appropriate version of Cython installed.

""" + branch_link) % {
        "branch_version": versioninfo.branch_version()
    }) + versioninfo.changes()),
    classifiers=[
        versioninfo.dev_status(), 'Intended Audience :: Developers',
        'Intended Audience :: Information Technology',
        'License :: OSI Approved :: BSD License',
        'Programming Language :: Cython',
        'Programming Language :: Python :: 2',
        'Programming Language :: Python :: 2.4',
        'Programming Language :: Python :: 2.5',
        'Programming Language :: Python :: 2.6',
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.1',
        'Programming Language :: Python :: 3.2',
        'Programming Language :: Python :: 3.3', 'Programming Language :: C',
        'Operating System :: OS Independent',
        'Topic :: Text Processing :: Markup :: HTML',
        'Topic :: Text Processing :: Markup :: XML',
        'Topic :: Software Development :: Libraries :: Python Modules'
    ],
    **setup_extra_options())

if OPTION_RUN_TESTS:
    print("Running tests.")
    import test
    sys.exit(test.main(sys.argv[:1]))
Пример #49
0
    def test_overall(self):
        """ Test via test frameworks.
        """
        import bfs1
        import bfs2
        import bfserr
        import test
        self.assertEqual([], test.main(''))
        self.assertEqual([], test.main('-v'))
        self.assertEqual([], test.main('-e edgelist.txt'))
        self.assertEqual([], test.main('-e edgelist.txt -v'))
        self.assertEqual([], test.main('-d 5 -m 7'))
        self.assertEqual([], test.main('-d 5 -m 7 -v'))
        self.assertEqual([], test.main('-r 1 -n 8000 -f 0.001'))
        self.assertEqual([], test.main('-r 1 -n 8000 -f 0.001 -v'))
        self.assertEqual([], test.main('-r 1 -n 1000 -f 0.001'))
        self.assertNotEqual([], test.test('',                example_err=True))
        self.assertNotEqual([], test.test('-e edgelist.txt', file_err=True))
        self.assertEqual([], test.test('', tree_err=True))  # it doesn't test
        self.assertNotEqual([], test.test('-r 1',            ran_err=True))
        self.assertRaisesRegexp(SystemExit, '0',
                                test.main, '-h')
        self.assertRaisesRegexp(SystemExit, str(test.invalid_input_exit_code),
                                test.main, '--invalid_option')
        self.assertRaisesRegexp(SystemExit, str(test.invalid_input_exit_code),
                                test.main, '-d a')
        self.assertRaisesRegexp(SystemExit, str(test.invalid_input_exit_code),
                                test.main, '-d -1')
        self.assertRaisesRegexp(SystemExit, str(test.invalid_input_exit_code),
                                test.main, '-m a')
        self.assertRaisesRegexp(SystemExit, str(test.invalid_input_exit_code),
                                test.main, '-m -1')
        self.assertRaisesRegexp(SystemExit, str(test.invalid_input_exit_code),
                                test.main, '-r a')
        self.assertRaisesRegexp(SystemExit, str(test.invalid_input_exit_code),
                                test.main, '-n a')
        self.assertRaisesRegexp(SystemExit, str(test.invalid_input_exit_code),
                                test.main, '-n -1')
        self.assertRaisesRegexp(SystemExit, str(test.invalid_input_exit_code),
                                test.main, '-f a')
        self.assertRaisesRegexp(SystemExit, str(test.invalid_input_exit_code),
                                test.main, '-f -1')

        self.assertEqual((0, [1]), bfs1.bfs1(1, 1, dict()))
        self.assertEqual((0, [1]), bfs2.bfs2(1, 1, dict()))
        self.assertIsNone(bfserr.bfserr_none(1, 1, dict()))
        self.assertNotEqual(0, bfserr.bfserr_len(1, 1, dict())[0])
        self.assertEqual(0, bfserr.bfserr_len(0, 1, dict())[0])
        self.assertNotEqual([1], bfserr.bfserr_node(1, 1, dict())[1])

        self.assertIsNone(bfs1.bfs1(0, 1, dict()))
        self.assertIsNone(bfserr.bfserr_none(0, 1, dict()))
        self.assertIsNone(bfserr.bfserr_node(0, 1, dict()))

        self.assertEqual((1, 0, [], 'el_arr'),
                         test.bfs_input_helper(True, 3, 4, [], 'el', [],
                                               {4:0, 3:1}))
        self.assertIsNone(test.bfs_output_helper(True, None, dict()))
        self.assertEqual((1, [3, 4]), test.bfs_output_helper(True,
                                                             (1, [1, 0]),
                                                             {0:4, 1:3}))

        self.assertNotEqual([], test.test_example([], [], [], False, True))
Пример #50
0
                with open(f_name, 'w') as f:
                    json.dump(config, f)


# generate_experiments()

with open("results.out", 'w') as out:
    sys.stdout = out
    if single_model:
        configs = [""]
    else:
        configs = os.listdir(path_to_experiment_configs)
    full_results = pd.DataFrame()
    for i in range(repetitions):
        for f in configs:
            print(f)
            if not single_model:
                copyfile(os.path.join(path_to_experiment_configs, f),
                         "config.json")
            environments, scores = test.main(algorithm)

            df = pd.DataFrame(scores)
            df['config'] = f
            df['env'] = environments
            df['rep'] = i
            df['mean'] = np.mean(scores, axis=1)
            df['std'] = np.std(scores, axis=1)
            full_results = full_results.append(df)

    full_results.to_csv(f'full_results_{algorithm.algorithm}.csv', index=False)
Пример #51
0
    i = 0
    while i < len(s):
        for k in KEEP:
            if s[i:i+len(k)] == k:
                r += k
                i += len(k)
                break
        else:
            if not s[i].isspace():
                r += s[i]
            i += 1
    print(r)
with open("maska-min.cpp", "w") as file:
    file.write(r)

print("= Compiling =")
compile_ok = 0 == system("g++ -O2 -pedantic -Wextra -Wall -std=c++98 -c maska-min.cpp -o maska-min.o")
if compile_ok: 
    compile_ok = 0 == system("g++ -O2 -pedantic -Wextra -Wall -std=c++98 -o maska-min.exe maska-min.o")
if compile_ok:
    print("= Testing =")
    test_ok = test.main("maska-min.exe", False)
else:
    test_ok = None
if compile_ok and test_ok:
    print("Success!")
    print(f"Length: {len(r)}")
else:
    print("Failure.")
    print(f"Compilation OK: {compile_ok}\nTests OK: {test_ok}")
system("pause")
# --------------------------------------------------------
# Deformable Convolutional Networks
# Copyright (c) 2017 Microsoft
# Licensed under The Apache-2.0 License [see LICENSE for details]
# Written by Yuwen Xiong
# --------------------------------------------------------

import os
import sys
os.environ['PYTHONUNBUFFERED'] = '1'
os.environ['MXNET_CUDNN_AUTOTUNE_DEFAULT'] = '0'
os.environ['MXNET_ENABLE_GPU_P2P'] = '0'
this_dir = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(this_dir, '..', '..', 'rfcn'))

import train_rfcn
import test

if __name__ == "__main__":
    train_rfcn.main()
    test.main()




Пример #53
0
    def post(self, request):

        tmp = json.dumps(test.main(request.POST.get('url')))
        return HttpResponse(tmp)
Пример #54
0
 def run(self):
     self.run_command('build')
     import test
     test.main()
Пример #55
0
def main():
  usage = "Usage: vcfPytools.py [tool] [options]\n\n" + \
          "Available tools:\n" + \
          "  annotate:\n\tAnnotate the vcf file with membership in other vcf files.\n" + \
          "  extract:\n\tExtract vcf records from a region.\n" + \
          "  filter:\n\tFilter the vcf file.\n" + \
          "  indel:\n\tIndel manipulation tools.\n" + \
          "  intersect:\n\tGenerate the intersection of two vcf files.\n" + \
          "  merge:\n\tMerge a list of vcf files.\n" + \
          "  multi:\n\tFind the intersections and unique fractions of multiple vcf files.\n" + \
          "  sort:\n\tSort a vcf file.\n" + \
          "  stats:\n\tGenerate statistics from a vcf file.\n" + \
          "  union:\n\tGenerate the union of two vcf files.\n" + \
          "  unique:\n\tGenerate the unique fraction from two vcf files.\n" + \
          "  validate:\n\tValidate the input vcf file.\n\n" + \
          "vcfPytools.py [tool] --help for information on a specific tool."

# Determine the requested tool.

  if len(sys.argv) > 1:
    tool = sys.argv[1]
  else:
    print >> sys.stderr, usage
    exit(1)

  if tool == "annotate":
    import annotate
    success = annotate.main()
  elif tool == "extract":
    import extract
    success = extract.main()
  elif tool == "filter":
    import filter
    success = filter.main()
  elif tool == "intersect":
    import intersect
    success = intersect.main()
  elif tool == "indel":
    import indel
    success = indel.main()
  elif tool == "multi":
    import multi
    success = multi.main()
  elif tool == "merge":
    import merge
    success = merge.main()
  elif tool == "sort":
    import sort
    success = sort.main()
  elif tool == "stats":
    import stats
    success = stats.main()
  elif tool == "union":
    import union
    success = union.main()
  elif tool == "unique":
    import unique
    success = unique.main()
  elif tool == "test":
    import test
    success = test.main()
  elif tool == "validate":
    import validate
    success = validate.main()
  elif tool == "--help" or tool == "-h" or tool == "?":
    print >> sys.stderr, usage
  else:
    print >> sys.stderr, "Unknown tool: ",tool
    print >> sys.stderr, "\n", usage
    exit(1)

# If program completed properly, terminate.

  if success == 0: exit(0)