Ejemplo n.º 1
0
def main_worker(local_rank, args):
    args.local_rank = local_rank
    dist.init_process_group(backend='nccl',
                            rank=local_rank,
                            world_size=args.world_size)
    torch.cuda.set_device(args.local_rank)

    #     network=nn.DataParallel(Xception(num_classes=cfg.num_classes))
    if local_rank == 0:
        network = torch.load(args.ckpt_path)

        dataloader = create_dataset_pytorch(args.data_path, is_train=False)
        with torch.no_grad():
            time_start = time.time()
            total_samples = 0.0
            correct_samples = 0.0
            for inputs, labels in dataloader:
                inputs = inputs.cuda()
                labels = labels.cuda()
                outputs = network(inputs)
                _, max_index = torch.max(outputs, dim=-1)
                total_samples += labels.size(0)
                correct_samples += (max_index == labels).sum()
            print('Accuracy: {}'.format(correct_samples / total_samples),
                  flush=True)
            time_end = time.time()
            time_step = time_end - time_start

        print('Finished Testing', flush=True)
        print('Finished Testing, Time:%f', time_step, flush=True)
Ejemplo n.º 2
0
    parser.add_argument('--ckpt_path',
                        type=str,
                        default="./checkpoint",
                        help='path where the checkpoint to be saved')
    parser.add_argument('--device_id',
                        type=int,
                        default=0,
                        help='device id of GPU. (Default: 0)')
    args = parser.parse_args()

    device = torch.device('cuda:' + str(args.device_id))
    network = torch.load(args.ckpt_path)
    network = network.module
    network.to(device)

    dataloader = create_dataset_pytorch(args.data_path, train=False)
    with torch.no_grad():
        total_samples = 0.0
        correct_samples = 0.0
        for inputs, labels in dataloader:
            inputs = inputs.to(device)
            labels = labels.to(device)
            outputs = network(inputs)
            _, max_index = torch.max(outputs, dim=-1)
            total_samples += labels.size(0)
            correct_samples += (max_index == labels).sum()
#         print('Accuracy: {}'.format(correct_samples / total_samples), flush=True)
        print(correct_samples * 1.0 / total_samples, flush=True)

#     print('Finished Testing', flush=True)
Ejemplo n.º 3
0
                        help='path where the dataset is saved')
    parser.add_argument('--ckpt_path',
                        type=str,
                        default="./checkpoint",
                        help='path where the checkpoint to be saved')
    parser.add_argument('--device_id',
                        type=int,
                        default=0,
                        help='device id of GPU. (Default: 0)')
    args = parser.parse_args()

    device = torch.device('cuda:' + str(args.device_id))
    network = torch.load(args.ckpt_path)
    network.to(device)

    dataloader = create_dataset_pytorch(args.data_path + "/val")
    with torch.no_grad():
        total_samples = 0.0
        correct_samples = 0.0
        for inputs, labels in dataloader:
            inputs = inputs.to(device)
            labels = labels.to(device)
            outputs = network(inputs)
            _, max_index = torch.max(outputs, dim=-1)
            total_samples += labels.size(0)
            correct_samples += (max_index == labels).sum()
        print('Accuracy: {}'.format(correct_samples / total_samples),
              flush=True)

    print('Finished Testing', flush=True)
Ejemplo n.º 4
0
                        help='path where the dataset is saved')
    parser.add_argument('--ckpt_path',
                        type=str,
                        default="./checkpoint",
                        help='path where the checkpoint to be saved')
    parser.add_argument('--device_id',
                        type=int,
                        default=0,
                        help='device id of GPU. (Default: 0)')
    args = parser.parse_args()

    device = torch.device('cuda:' + str(args.device_id))
    network = torch.load(args.ckpt_path)
    network.to(device)

    dataloader = create_dataset_pytorch(args.data_path, is_train=True)
    with torch.no_grad():
        total_samples = 0.0
        correct_samples = 0.0
        for inputs, labels in dataloader:
            inputs = inputs.to(device)
            labels = labels.to(device)
            outputs = network(inputs)
            _, max_index = torch.max(outputs, dim=-1)
            total_samples += labels.size(0)
            correct_samples += (max_index == labels).sum()
        print('Accuracy: {}'.format(correct_samples / total_samples),
              flush=True)

    print('Finished Testing', flush=True)
Ejemplo n.º 5
0
    args = parser.parse_args()

    network = Xception(num_classes=cfg.num_classes)
    network = network.cuda()
    network = nn.DataParallel(network)
    criterion = nn.CrossEntropyLoss()
    #     optimizer = optim.RMSprop(network.parameters(),
    #                                 lr=cfg.lr_init,
    #                                 eps=cfg.rmsprop_epsilon,
    #                                 momentum=cfg.rmsprop_momentum,
    #                                 alpha=cfg.rmsprop_decay)
    optimizer = optim.SGD(network.parameters(),
                          lr=cfg.lr_init,
                          momentum=cfg.SGD_momentum)
    # prepare data
    dataloader = create_dataset_pytorch(args.data_path,
                                        n_workers=cfg.n_workers)
    step_per_epoch = len(dataloader)
    print("step_per_epoch =", step_per_epoch)
    scheduler = optim.lr_scheduler.StepLR(optimizer,
                                          gamma=cfg.lr_decay_rate,
                                          step_size=cfg.lr_decay_epoch *
                                          step_per_epoch)
    q_ckpt = Queue(maxsize=cfg.keep_checkpoint_max)

    global_step_id = 0
    for epoch in range(cfg.epoch_size):
        time_epoch = 0.0
        torch.cuda.synchronize()
        for i, data in enumerate(dataloader):
            time_start = time.time()
            inputs, labels = data