Beispiel #1
0
def test_kitti_2012(cfg, model, gt_flows, noc_masks):
    dataset = KITTI_2012(cfg.gt_2012_dir)
    flow_list = []
    for idx, inputs in enumerate(tqdm(dataset)):
        img, K, K_inv = inputs
        img = img[None, :, :, :]
        K = K[None, :, :]
        K_inv = K_inv[None, :, :]
        img_h = int(img.shape[2] / 2)
        img1, img2 = img[:, :, :img_h, :], img[:, :, img_h:, :]
        img1, img2, K, K_inv = img1.cuda(), img2.cuda(), K.cuda(), K_inv.cuda()
        if cfg.mode == 'flow' or cfg.mode == 'flowposenet':
            flow = model.inference_flow(img1, img2)
        else:
            flow, _, _, _, _, _ = model.inference(img1, img2, K, K_inv)
        # pdb.set_trace()
        flow = flow[0].detach().cpu().numpy()
        flow = flow.transpose(1, 2, 0)
        flow_list.append(flow)

    eval_flow_res = eval_flow_avg(gt_flows,
                                  noc_masks,
                                  flow_list,
                                  cfg,
                                  write_img=False)

    print('CONFIG: {0}, mode: {1}'.format(cfg.config_file, cfg.mode))
    print('[EVAL] [KITTI 2012]')
    print(eval_flow_res)
    return eval_flow_res
Beispiel #2
0
def test_kitti_2015(cfg,
                    model,
                    gt_flows,
                    noc_masks,
                    gt_masks,
                    depth_save_dir=None):
    dataset = KITTI_2015(cfg.gt_2015_dir)
    visualizer = Visualizer_debug(depth_save_dir)
    pred_flow_list = []
    pred_disp_list = []
    img_list = []
    for idx, inputs in enumerate(tqdm(dataset)):
        img, K, K_inv = inputs
        img = img[None, :, :, :]
        K = K[None, :, :]
        K_inv = K_inv[None, :, :]
        img_h = int(img.shape[2] / 2)
        img1, img2 = img[:, :, :img_h, :], img[:, :, img_h:, :]
        img_list.append(img1)
        img1, img2, K, K_inv = img1.cuda(), img2.cuda(), K.cuda(), K_inv.cuda()
        if cfg.mode == 'flow' or cfg.mode == 'flowposenet':
            flow = model.inference_flow(img1, img2)
        else:
            flow, disp1, disp2, Rt, _, _ = model.inference(
                img1, img2, K, K_inv)
            disp = disp1[0].detach().cpu().numpy()
            disp = disp.transpose(1, 2, 0)
            pred_disp_list.append(disp)

        flow = flow[0].detach().cpu().numpy()
        flow = flow.transpose(1, 2, 0)
        pred_flow_list.append(flow)

    # pdb.set_trace()
    eval_flow_res = eval_flow_avg(gt_flows,
                                  noc_masks,
                                  pred_flow_list,
                                  cfg,
                                  moving_masks=gt_masks,
                                  write_img=False)
    print('CONFIG: {0}, mode: {1}'.format(cfg.config_file, cfg.mode))
    print('[EVAL] [KITTI 2015]')
    print(eval_flow_res)
    # depth evaluation
    return eval_flow_res