Esempio n. 1
0
def sgd_optimize_logreg(datasets):
    x = T.matrix('x')    # the data is presented as rasterized images
    y = T.ivector('y')   # the labels are presented as 1D vector of [int] labels

    classifier = LogisticRegression(input=x, n_in=28 * 28, n_out=10)

    trainer = SGDTrainer(classifier, datasets)
    trainer.build(x, y)
    return trainer.train()
Esempio n. 2
0
def sgd_optimize_mlp(datasets):
    x = T.matrix('x')    # the data is presented as rasterized images
    y = T.ivector('y')   # the labels are presented as 1D vector of [int] labels

    classifier = MLP(input=x, n_in=28 * 28, n_out=10, n_hiddens=[1500])

    trainer = SGDTrainer(classifier, datasets, learning_rate=0.01, L1_reg=0.0001,
                         L2_reg=0.001, n_epochs=500, batch_size=20)
    trainer.build(x, y)
    return trainer.train()
Esempio n. 3
0
def sgd_optimize_lenet(datasets):
    x = T.matrix('x')    # the data is presented as rasterized images
    y = T.ivector('y')   # the labels are presented as 1D vector of [int] labels

    classifier = LeNet(input=x, nkerns=[20, 50], filter_shapes=[[5, 5], [5, 5]],
                        image_shapes=[[28, 28], [12, 12]], batch_size=500,
                        n_hidden=[500], n_out=10)

    trainer = SGDTrainer(classifier, datasets, learning_rate=0.01,
                         L1_reg=0.0001, L2_reg=0.001, n_epochs=100,
                         batch_size=classifier.batch_size)
    trainer.build(x, y)
    return trainer.train()
Esempio n. 4
0
def main():
    parser = argparse.ArgumentParser(description="ReID Baseline Training")
    parser.add_argument("--config_file",
                        default="",
                        help="path to config file",
                        type=str)
    parser.add_argument("opts",
                        help="Modify config options using the command-line",
                        default=None,
                        nargs=argparse.REMAINDER)
    args = parser.parse_args()
    if args.config_file != "":
        cfg.merge_from_file(args.config_file)
    cfg.merge_from_list(args.opts)
    cfg.freeze()

    output_dir = cfg.OUTPUT_DIR
    if output_dir and not os.path.exists(output_dir):
        os.makedirs(output_dir)
    num_gpus = torch.cuda.device_count()
    logger = setup_logger('reid_baseline', output_dir, 0)
    logger.info('Using {} GPUS'.format(num_gpus))
    logger.info('Running with config:\n{}'.format(cfg))
    train_dl, val_dl, num_query, num_classes = make_dataloader(cfg, num_gpus)
    model = build_model(cfg, num_classes)
    loss = make_loss(cfg, num_classes)
    trainer = SGDTrainer(cfg, model, train_dl, val_dl, loss, num_query,
                         num_gpus)
    logger.info('train transform: \n{}'.format(train_dl.dataset.transform))
    logger.info('valid transform: \n{}'.format(val_dl.dataset.transform))
    logger.info(type(model))
    logger.info(loss)
    logger.info(trainer)
    for epoch in range(trainer.epochs):
        for batch in trainer.train_dl:
            trainer.step(batch)
            trainer.handle_new_batch()
        trainer.handle_new_epoch()