Exemplo n.º 1
0
def evaluate_icp(args, test_loader):
    dura = []
    t_errors, R_errors, degree_errors = [], [], []

    for i, (ref_cloud, src_cloud, gtR, gtt) in tqdm(enumerate(test_loader)):
        if args.cuda:
            ref_cloud, src_cloud, gtR, gtt = ref_cloud.cuda(), src_cloud.cuda(), \
                                             gtR.cuda(), gtt.cuda()

        ref_cloud = torch.squeeze(ref_cloud).cpu().numpy()
        src_cloud = torch.squeeze(src_cloud).cpu().numpy()

        tic = time.time()
        R, t, pred_ref_cloud = icp(npy2pcd(src_cloud), npy2pcd(ref_cloud))
        toc = time.time()
        R = torch.from_numpy(np.expand_dims(R, 0)).to(gtR)
        t = torch.from_numpy(np.expand_dims(t, 0)).to(gtt)
        dura.append(toc - tic)
        cur_t_error = translation_error(t, -gtt)
        cur_R_error = rotation_error(R, gtR.permute(0, 2, 1).contiguous())
        cur_degree_error = degree_error(R, gtR.permute(0, 2, 1).contiguous())
        t_errors.append(cur_t_error.item())
        R_errors.append(cur_R_error.item())
        degree_errors.append(cur_degree_error.item())

        if args.show:
            print(cur_t_error.item(), cur_R_error.item(),
                  cur_degree_error.item())
            pcd1 = npy2pcd(ref_cloud, 0)
            pcd2 = npy2pcd(src_cloud, 1)
            pcd3 = pred_ref_cloud
            o3d.visualization.draw_geometries([pcd1, pcd2, pcd3])
    return dura, np.mean(t_errors), np.mean(R_errors), np.mean(degree_errors)
Exemplo n.º 2
0
def evaluate_benchmark(args, test_loader):
    model = IterativeBenchmark(in_dim1=args.in_dim, niters=args.niters)
    if args.cuda:
        model = model.cuda()
        model.load_state_dict(torch.load(args.checkpoint))
    else:
        model.load_state_dict(
            torch.load(args.checkpoint, map_location=torch.device('cpu')))
    model.eval()

    dura = []
    t_errors, R_errors, degree_errors = [], [], []
    with torch.no_grad():
        for i, (ref_cloud, src_cloud, gtR,
                gtt) in tqdm(enumerate(test_loader)):
            if args.cuda:
                ref_cloud, src_cloud, gtR, gtt = ref_cloud.cuda(), src_cloud.cuda(), \
                                                 gtR.cuda(), gtt.cuda()
            tic = time.time()
            R, t, pred_ref_cloud = model(
                src_cloud.permute(0, 2, 1).contiguous(),
                ref_cloud.permute(0, 2, 1).contiguous())
            toc = time.time()
            dura.append(toc - tic)

            cur_t_error = translation_error(t, -gtt)
            cur_R_error = rotation_error(R, gtR.permute(0, 2, 1).contiguous())
            cur_degree_error = degree_error(R,
                                            gtR.permute(0, 2, 1).contiguous())
            t_errors.append(cur_t_error.item())
            R_errors.append(cur_R_error.item())
            degree_errors.append(cur_degree_error.item())

            if args.show:
                print(cur_t_error.item(), cur_R_error.item(),
                      cur_degree_error.item())
                ref_cloud = torch.squeeze(ref_cloud).cpu().numpy()
                src_cloud = torch.squeeze(src_cloud).cpu().numpy()
                pred_ref_cloud = torch.squeeze(pred_ref_cloud).cpu().numpy()
                pcd1 = npy2pcd(ref_cloud, 0)
                pcd2 = npy2pcd(src_cloud, 1)
                pcd3 = npy2pcd(pred_ref_cloud, 2)
                o3d.visualization.draw_geometries([pcd1, pcd2, pcd3])
    return dura, np.mean(t_errors), np.mean(R_errors), np.mean(degree_errors)
Exemplo n.º 3
0
def test_one_epoch(test_loader, model, loss_fn):
    model.eval()
    losses, t_errors, R_errors, degree_errors = [], [], [], []
    with torch.no_grad():
        for ref_cloud, src_cloud, gtR, gtt in tqdm(test_loader):
            ref_cloud, src_cloud, gtR, gtt = ref_cloud.cuda(), src_cloud.cuda(), \
                                             gtR.cuda(), gtt.cuda()
            R, t, pred_ref_cloud = model(
                src_cloud.permute(0, 2, 1).contiguous(),
                ref_cloud.permute(0, 2, 1).contiguous())
            loss = loss_fn(ref_cloud, pred_ref_cloud)
            cur_t_error = translation_error(t, -gtt)
            cur_R_error = rotation_error(R, gtR.permute(0, 2, 1).contiguous())
            cur_degree_error = degree_error(R,
                                            gtR.permute(0, 2, 1).contiguous())
            losses.append(loss.item())
            t_errors.append(cur_t_error.item())
            R_errors.append(cur_R_error.item())
            degree_errors.append(cur_degree_error.item())
    model.train()
    return np.mean(losses), np.mean(t_errors), np.mean(R_errors), np.mean(
        degree_errors)
Exemplo n.º 4
0
def train_one_epoch(train_loader, model, loss_fn, optimizer):
    losses, t_errors, R_errors, degree_errors = [], [], [], []
    for ref_cloud, src_cloud, gtR, gtt in tqdm(train_loader):
        ref_cloud, src_cloud, gtR, gtt = ref_cloud.cuda(), src_cloud.cuda(), \
                                         gtR.cuda(), gtt.cuda()
        optimizer.zero_grad()
        R, t, pred_ref_cloud = model(
            src_cloud.permute(0, 2, 1).contiguous(),
            ref_cloud.permute(0, 2, 1).contiguous())
        loss = loss_fn(ref_cloud, pred_ref_cloud)
        loss.backward()
        optimizer.step()

        cur_t_error = translation_error(t, -gtt)
        cur_R_error = rotation_error(R, gtR.permute(0, 2, 1).contiguous())
        cur_degree_error = degree_error(R, gtR.permute(0, 2, 1).contiguous())
        losses.append(loss.item())
        t_errors.append(cur_t_error.item())
        R_errors.append(cur_R_error.item())
        degree_errors.append(cur_degree_error.item())
    return np.mean(losses), np.mean(t_errors), np.mean(R_errors), np.mean(
        degree_errors)