MCPcopy Create free account
hub / github.com/QWTforGithub/T2LDM / sparse_quantize

Function sparse_quantize

eval/metric_utils.py:46–69  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

44
45
46def 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
72def pcd2range(pcd, size, fov, depth_range, remission=None, labels=None, **kwargs):

Callers 5

pcd2voxelFunction · 0.85
pcd2voxel_fullFunction · 0.85
pcd2bev_sumFunction · 0.85
pcd2bev_binFunction · 0.85
bev_sampleFunction · 0.85

Calls 1

ravel_hashFunction · 0.85

Tested by

no test coverage detected