Exemplo n.º 1
0
def main():
    parser = opts.get_parser()
    args = parser.parse_args()
    params = read_params(args)
    out_dir = make_and_fill_output_dir(args, params)
    load_unspecified_params(params)

    # Initialize model and move it to gpu
    torch.cuda.set_device(args.gpu)
    model = gen_model(params, args)
    print(model)
    model.cuda(args.gpu)

    # Load the datasets and setup optimizer
    datasets, dataset_stats = load_data(args.data)
    optimizer = setup_optimizer(model, params)

    if args.eval:
        dev_epoch(model=model,
                  data_iter=datasets["dev"].get_batched_iter(
                      params["batch_size"]),
                  desc="Evaluation:",
                  data_iter_len=dataset_stats["dev"]["words"] //
                  params["batch_size"])
    else:
        n_epochs = int(args.n_epochs)
        for i in range(1, n_epochs + 1):
            run_epoch(model=model,
                      optimizer=optimizer,
                      datasets=datasets,
                      dataset_stats=dataset_stats,
                      out_dir=out_dir,
                      batch_size=params["batch_size"],
                      bptt_len=params["bptt_len"],
                      epoch_num=i)
Exemplo n.º 2
0
def main():
    parser = opts.get_parser()
    args = parser.parse_args()
    params = read_params(args)
    make_and_fill_output_dir(args, params)
    load_unspecified_params(params)

    # Initialize model and move it to gpu
    torch.cuda.set_device(args.gpu)
    model = gen_model(params, args.resume_from)
    model.cuda(args.gpu)
    model.init_params()

    # Load the datasets and setup optimizer
    datasets, dataset_stats = load_data(args.data)
    optimizer = setup_optimizer(model)

    n_epochs = int(args.n_epochs)
    for i in range(1, n_epochs + 1):
        run_epoch(model=model,
                  optimizer=optimizer,
                  datasets=datasets,
                  dataset_stats=dataset_stats,
                  batch_size=params["batch_size"],
                  bptt_len=params["bptt_len"],
                  epoch_num=i)
Exemplo n.º 3
0
def main():
    parser = opts.get_parser()
    args = parser.parse_args()
    params = read_params(args)
    make_and_fill_output_dir(args, params)
    load_unspecified_params(params)

    # Initialize model and move it to gpu
    model = gen_model(params, args.resume_from)
    model_to_gpu(model, args.gpu)

    # Load the datasets and setup optimizer
    datasets, dataset_stats = load_data(args.data)
    optimizer = setup_optimizer(model)

    n_epochs = int(args.n_epochs)
    for i in range(1, n_epochs + 1):
        run_epoch(model=model,
                  optimizer=optimizer,
                  datasets=datasets,
                  dataset_stats=dataset_stats,
                  batch_size=params["batch_size"],
                  bptt_len=params["bptt_len"],
                  epoch_num=i)
        save_model(path.join(args.out, "snapshot_{0}".format(i)), model)
Exemplo n.º 4
0
def main():
    parser = get_parser()
    p = parser.parse_args()
    if p.config is not None:
        with open(p.config, 'r') as f:
            default_arg = yaml.load(f)
        key = vars(p).keys()
        for k in default_arg.keys():
            if k not in key:
                print('Wrong Arg: {}'.format(k))
                assert (k in key)
        parser.set_defaults(**default_arg)
    args = parser.parse_args()
    processor = Processor(args)
    processor.start()
Exemplo n.º 5
0
def main(opts):
    """docstring for main"""
    if opts.mode == "colab_tpu":
        strategy = start_tpu()
        t = trainer(opts, strategy)
        t.train()

    elif opts.mode == "gpu":
        opts.shuffle_buffer = 64
        opts.val_batch_size = 32
        opts.train_batch_size = 32
        strategy = tf.distribute.get_strategy()
        t = trainer(opts, strategy)
        t.train()

    elif opts.mode == "debug":
        opts.shuffle_buffer = None
        opts.val_batch_size = 1
        opts.train_batch_size = 1
        strategy = tf.distribute.get_strategy()
        t = trainer(opts, strategy)
        t.train()


if __name__ == "__main__":
    opts = get_parser()
    num_data = opts.tfrecord_path.split('/')[-1].split('.')[0].split('_')[-1]
    opts.num_data = int(num_data)
    opts.weight_path = opts.weight_path + opts.exp_name
    main(opts)