Exemplo n.º 1
0
    apm.reset()
    print('val-{} Loss: {:.4f} Acc: {:.4f}'.format(dataloader.root, epoch_loss,
                                                   error))

    return full_probs, epoch_loss


if __name__ == '__main__':

    if args.mode == 'flow':
        dataloaders, datasets = load_data(train_split, test_split, flow_root)
    elif args.mode == 'rgb':
        dataloaders, datasets = load_data(train_split, test_split, rgb_root)

    if args.train:
        model = super_event.get_super_event_model(0, classes)
        criterion = nn.NLLLoss(reduce=False)

        lr = 0.1 * batch_size / len(datasets['train'])
        print(lr)
        optimizer = optim.Adam(model.parameters(), lr=lr)
        lr_sched = optim.lr_scheduler.ReduceLROnPlateau(optimizer,
                                                        patience=3,
                                                        verbose=True)

        run([(model, 0, dataloaders, optimizer, lr_sched, args.model_file)],
            criterion,
            num_epochs=40)

    else:
        print('Evaluating...')
    apm.reset()
    print 'val-{} Loss: {:.4f} Acc: {:.4f}'.format(dataloader.root, epoch_loss,
                                                   error)

    return full_probs, epoch_loss


if __name__ == '__main__':

    if args.mode == 'flow':
        dataloaders, datasets = load_data(train_split, test_split, flow_root)
    elif args.mode == 'rgb':
        dataloaders, datasets = load_data(train_split, test_split, rgb_root)

    if args.train:
        model = super_event.get_super_event_model(0, classes)
        criterion = nn.NLLLoss(reduce=False)

        lr = 0.1 * batch_size / len(datasets['train'])
        print lr
        optimizer = optim.Adam(model.parameters(), lr=lr)
        lr_sched = optim.lr_scheduler.ReduceLROnPlateau(optimizer,
                                                        patience=3,
                                                        verbose=True)

        run([(model, 0, dataloaders, optimizer, lr_sched, args.model_file)],
            criterion,
            num_epochs=40)

    else:
        print 'Evaluating...'