Modified based on https://github.com/mit-han-lab/torchsparse/blob/462dea4a701f87a7545afb3616bf2cf53dd404f3/torchsparse/utils/quantize.py
(coords, voxel_size: Union[float, Tuple[float, ...]] = 1, *, return_index: bool = False,
return_inverse: bool = False)
| 44 | |
| 45 | |
| 46 | def sparse_quantize(coords, voxel_size: Union[float, Tuple[float, ...]] = 1, *, return_index: bool = False, |
| 47 | return_inverse: bool = False) -> List[np.ndarray]: |
| 48 | """ |
| 49 | Modified based on https://github.com/mit-han-lab/torchsparse/blob/462dea4a701f87a7545afb3616bf2cf53dd404f3/torchsparse/utils/quantize.py |
| 50 | |
| 51 | """ |
| 52 | if isinstance(voxel_size, (float, int)): |
| 53 | voxel_size = tuple(repeat(voxel_size, coords.shape[1])) |
| 54 | assert isinstance(voxel_size, tuple) and len(voxel_size) in [2, 3] # support 2D and 3D coordinates only |
| 55 | |
| 56 | voxel_size = np.array(voxel_size) |
| 57 | coords = np.floor(coords / voxel_size).astype(np.int32) |
| 58 | |
| 59 | _, indices, inverse_indices = np.unique( |
| 60 | ravel_hash(coords), return_index=True, return_inverse=True |
| 61 | ) |
| 62 | coords = coords[indices] |
| 63 | |
| 64 | outputs = [coords] |
| 65 | if return_index: |
| 66 | outputs += [indices] |
| 67 | if return_inverse: |
| 68 | outputs += [inverse_indices] |
| 69 | return outputs[0] if len(outputs) == 1 else outputs |
| 70 | |
| 71 | |
| 72 | def pcd2range(pcd, size, fov, depth_range, remission=None, labels=None, **kwargs): |
no test coverage detected