예제 #1
0
 def test_write_npy(self):
     from det3.ops import read_npy, write_npy
     data = np.random.randn(1000).astype(np.float32)
     path = "./unit-test/result/test_write_npy.npy"
     write_npy(data, path)
     est = read_npy(path)
     gt = data
     self.assertTrue(np.array_equal(gt, est))
예제 #2
0
 def test_get_pts_idx(self):
     from det3.ops import crop_pts_3drot, read_npy
     from det3.dataloader.carladata import CarlaObj, CarlaObj, CarlaLabel, CarlaCalib
     pts = read_npy("./unit-test/data/test_CarlaAugmentor_000250.npy")
     calib = CarlaCalib(
         "./unit-test/data/test_CarlaAugmentor_000250_calib.txt"
     ).read_calib_file()
     label = CarlaLabel(
         "./unit-test/data/test_CarlaAugmentor_000250_label_imu.txt"
     ).read_label_file()
     pts = calib.lidar2imu(pts, key='Tr_imu_to_velo_top')
     for i in range(len(label)):
         obj = UdiObj(arr=np.array(label.bboxes3d[i,
                                                  [3, 4, 5, 2, 1, 0, 6]]),
                      cls="Car",
                      score=0.99)
         idx = obj.get_pts_idx(pts)
         gt = label.data[i].get_pts_idx(pts)
         gt = np.where(gt)[0].flatten()
         self.assertTrue(set(idx.tolist()) == set(gt.tolist()))
예제 #3
0
파일: lyftdata.py 프로젝트: pyun-ram/det3
 def read_data(self):
     '''
     -> res: dict
         res[calib]: LyftCalib / None
         res[label]: LyftLabel / None
         res[pc]: dict {lidar: np.ndarray (#pts, >=3) (in Flidar)} / None
     '''
     calib = LyftCalib(self._calib_path).read_calib_file() if self._output_dict["calib"] else None
     label = LyftLabel(self._label_path).read_label_file() if self._output_dict["label"] else None
     if self._output_dict["lidar"]:
         pc = dict()
         for k, v in self._lidar_paths.items():
             pc[k] = read_npy(v).reshape(-1, 4)
     else:
         pc = None
     res = {k: None for k in self._output_dict.keys()}
     res["calib"] = calib
     res["label"] = label
     res["lidar"] = pc
     return res
예제 #4
0
 def test_corner_transformation(self):
     from det3.ops import crop_pts_3drot, read_npy
     from det3.dataloader.carladata import CarlaObj, CarlaObj, CarlaLabel, CarlaCalib
     pts = read_npy("./unit-test/data/test_CarlaAugmentor_000250.npy")
     calib = CarlaCalib(
         "./unit-test/data/test_CarlaAugmentor_000250_calib.txt"
     ).read_calib_file()
     label = CarlaLabel(
         "./unit-test/data/test_CarlaAugmentor_000250_label_imu.txt"
     ).read_label_file()
     pts = calib.lidar2imu(pts, key='Tr_imu_to_velo_top')
     for i in range(len(label)):
         obj = UdiObj(arr=np.array(label.bboxes3d[i,
                                                  [3, 4, 5, 2, 1, 0, 6]]),
                      cls="Car",
                      score=0.99)
         cns = obj.get_bbox3d_corners()
         gt = label.data[i].get_bbox3dcorners()
         self.assertTrue(np.allclose(cns, gt, atol=1e-2))
         obj_cp = UdiObj()
         obj_cp.from_corners(cns, obj.cls, obj.score)
         self.assertTrue(obj_cp.equal(obj))
예제 #5
0
 def test_crop_pts_3drot(self):
     print("test_crop_pts_3drot")
     from det3.ops import crop_pts_3drot, read_npy
     from det3.dataloader.carladata import CarlaObj, CarlaObj, CarlaLabel, CarlaCalib
     pts = read_npy("./unit-test/data/test_CarlaAugmentor_000250.npy")
     calib = CarlaCalib(
         "./unit-test/data/test_CarlaAugmentor_000250_calib.txt"
     ).read_calib_file()
     label = CarlaLabel(
         "./unit-test/data/test_CarlaAugmentor_000250_label_imu.txt"
     ).read_label_file()
     pts = calib.lidar2imu(pts, key='Tr_imu_to_velo_top')
     for test_dtype in [np.float32, np.float64]:
         # obj.h, obj.w, obj.l, obj.x, obj.y, obj.z, obj.ry
         boxes = label.bboxes3d[:, [3, 4, 5, 2, 1, 0, 6]].astype(test_dtype)
         pts = pts.astype(test_dtype)
         gt = [obj.get_pts_idx(pts) for obj in label.data]
         gt = [np.where(itm)[0].flatten() for itm in gt]
         # np
         est = crop_pts_3drot(boxes, pts)
         self.assertTrue(len(gt) == len(est))
         for gt_, est_ in zip(gt, est):
             set_gt = set(gt_.tolist())
             set_est = set(est_.tolist())
             self.assertTrue(set_gt == set_est)
         times = 1000
         t1 = time.time()
         for i in range(times):
             est = crop_pts_3drot(boxes, pts)
         t = (time.time() - t1) / times * 1000
         print(f"np {times}: {t:.3f} ms {est[0].dtype}")
         # torch
         pts_ts = torch.from_numpy(pts)
         boxes_ts = torch.from_numpy(boxes)
         est_ts = crop_pts_3drot(boxes_ts, pts_ts)
         self.assertTrue(len(gt) == len(est_ts))
         for gt_, est_ts_ in zip(gt, est_ts):
             set_gt = set(gt_.tolist())
             set_est_ts = set(est_ts_.numpy().tolist())
             self.assertTrue(set_gt == set_est_ts)
         t1 = time.time()
         for i in range(times):
             est_ts = crop_pts_3drot(boxes_ts, pts_ts)
         t = (time.time() - t1) / times * 1000
         print(f"torchcpu {times}: {t:.3f} ms {est_ts[0].dtype}")
         # torchgpu
         pts_tsgpu = torch.from_numpy(pts).cuda()
         boxes_tsgpu = torch.from_numpy(boxes).cuda()
         est_tsgpu = crop_pts_3drot(boxes_tsgpu, pts_tsgpu)
         self.assertTrue(len(gt) == len(est_tsgpu))
         for gt_, est_tsgpu_ in zip(gt, est_tsgpu):
             set_gt = set(gt_.tolist())
             set_est_tsgpu = set(est_tsgpu_.cpu().numpy().tolist())
             self.assertTrue(set_gt == set_est_tsgpu)
         torch.cuda.synchronize()
         t1 = time.time()
         for i in range(times):
             est_tsgpu = crop_pts_3drot(boxes_tsgpu, pts_tsgpu)
         torch.cuda.synchronize()
         t = (time.time() - t1) / times * 1000
         print(f"torchgpu {times}: {t:.3f} ms {est_tsgpu[0].dtype}")
예제 #6
0
 def test_read_npy(self):
     from det3.ops import read_npy, write_npy
     gt = np.random.randn(1000).astype(np.float32)
     np.save("./unit-test/result/test_read_npy.npy", gt)
     est = read_npy("./unit-test/result/test_read_npy.npy")
     self.assertTrue(np.array_equal(gt, est))