Пример #1
0
def main():
    parser = argparse.ArgumentParser(add_help=True)
    parser.add_argument('--config', help="Path to config file.")

    args, _ = parser.parse_known_args()

    configfile = args.config or {'run1': {}}
    configs = Config(configfile)
    for run in configs:
        print("create submission for: ", run)
        resultpath = os.path.join(resultspath, run)
        if not os.path.exists(resultpath):
            os.makedirs(resultpath)
        submissionfile = os.path.join(resultpath, 'submission.csv')
        if os.path.exists(submissionfile):
            os.remove(submissionfile)

        # get config for current run
        config = configs.get()

        backends.set_backend(config['backend'])
        # Load Model
        modelfile = os.path.join('results/', run, 'model.checkpoint')
        model = Model(config, modelfile)
        # dataloader
        dataloader = DataLoader(config=config, mode='test')
        # predictor
        predictor = Predictor(model=model,
                              config=config,
                              backend=backends.backend())

        with open(submissionfile, 'a') as f:
            f.write('img,pixels\n')
            for index, (img, filename) in enumerate(dataloader):
                print('{}/{}'.format(index + 1, len(dataloader)))

                mask = predictor.predict(img)
                mask = cv2.resize(
                    mask, (config['orig_width'], config['orig_height']),
                    interpolation=cv2.INTER_NEAREST)
                save = False
                if save:
                    imgfile = os.path.join(
                        resultpath,
                        os.path.basename(filename).split(".")[0] + ".png")
                    cv2.imwrite(imgfile, mask * 255)
                enc = run_length_enc(mask)
                f.write('{},{}\n'.format(
                    os.path.basename(filename).split(".")[0],
                    ' '.join(map(str, enc))))
    sys.exit(0)
Пример #2
0
def main():
    parser = argparse.ArgumentParser(add_help=True)
    parser.add_argument('--config', help="Path to config file.")

    args, _ = parser.parse_known_args()

    configfile = args.config or {'run1': {}}
    configs = Config(configfile)
    for run in configs:
        print("Run: ", run)
        resultpath = os.path.join(resultspath, run)
        if not os.path.exists(resultpath):
            os.makedirs(resultpath)
        configs.save(resultpath + '/config.yml')
        # get config for current run
        config = configs.get()
        # set backend
        backends.set_backend(config['backend'])
        # summary
        summarywriter = backends.backend().get_summary_writer(
            logdir=resultpath)
        # Load Model
        modelfile = os.path.join('results/', run, 'model.checkpoint')
        model = Model(config, modelfile)
        # augmentation
        augmentation = Augmentation(config=config)
        # data loader
        dataloader = DataLoader(config=config,
                                mode='train',
                                augmentation=augmentation)
        # validation data loader
        valdataloader = DataLoader(config=config, mode='val')
        trainer = Trainer(config,
                          model,
                          dataloader,
                          valdataloader=valdataloader,
                          summarywriter=summarywriter)
        trainer.train()

    report = Report(configs, resultspath)
    report.generate()
    sys.exit(0)
Пример #3
0
from protoseg import Report
from protoseg import HyperParamOptimizer
from protoseg import backends

resultspath = 'results/'

def help():
    return "Config file parameter missing. Run like: python train.py /path/to/config.yml 100, where 100 is max_evals."


if __name__ == "__main__":
    max_evals = 10
    if len(sys.argv) < 2:
        print(help())
        sys.exit(1)
    configs = Config(sys.argv[1])
    if len(sys.argv) > 2:
        max_evals = int(sys.argv[2])

    report = Report(configs, resultspath)
    for run in configs:
        print("Run: ", run)
        resultpath = os.path.join(resultspath, run)
        if not os.path.exists(resultpath):
            os.makedirs(resultpath)
        configs.save(resultpath + '/config.yml')
        # get config for current run
        config = configs.get()
        # set backend
        backends.set_backend(config['backend'])
        # summary
Пример #4
0
def test_len():
    config = Config(configs=configs)
    assert(len(config), 2)
Пример #5
0
def test_iterator():
    count = 0
    config = Config(configs=configs)
    for _ in config:
        count += 1
    assert(count, 2)
Пример #6
0
def test_index():
    config = Config(configs=configs)
    assert(config[0], 'run1')
    assert(config[1], 'run2')
Пример #7
0
    length = end - start
    res = [[s + 1, l + 1] for s, l in zip(list(start), list(length))]
    res = list(chain.from_iterable(res))
    return res  # ' '.join([str(r) for r in res])


def help():
    return "Config file parameter missing. Run like: python submit.py /path/to/config.yml"


if __name__ == "__main__":
    if len(sys.argv) < 2:
        print(help())
        sys.exit(1)

    configs = Config(sys.argv[1])
    for run in configs:
        print("create submission for: ", run)
        resultpath = os.path.join(resultspath, run)
        if not os.path.exists(resultpath):
            os.makedirs(resultpath)
        submissionfile = os.path.join(resultpath, 'submission.csv')
        if os.path.exists(submissionfile):
            os.remove(submissionfile)

        # get config for current run
        config = configs.get()

        backends.set_backend(config['backend'])
        # summary
        summarywriter = backends.backend().get_summary_writer(