MCPcopy Create free account
hub / github.com/NVIDIA/MinkowskiEngine / sparse_quantize

Function sparse_quantize

MinkowskiEngine/utils/quantization.py:125–330  ·  view source on GitHub ↗

r"""Given coordinates, and features (optionally labels), the function generates quantized (voxelized) coordinates. Args: :attr:`coordinates` (:attr:`numpy.ndarray` or :attr:`torch.Tensor`): a matrix of size :math:`N \times D` where :math:`N` is the number of points i

(
    coordinates,
    features=None,
    labels=None,
    ignore_label=-100,
    return_index=False,
    return_inverse=False,
    return_maps_only=False,
    quantization_size=None,
    device="cpu",
)

Source from the content-addressed store, hash-verified

123
124
125def sparse_quantize(
126 coordinates,
127 features=None,
128 labels=None,
129 ignore_label=-100,
130 return_index=False,
131 return_inverse=False,
132 return_maps_only=False,
133 quantization_size=None,
134 device="cpu",
135):
136 r"""Given coordinates, and features (optionally labels), the function
137 generates quantized (voxelized) coordinates.
138
139 Args:
140 :attr:`coordinates` (:attr:`numpy.ndarray` or :attr:`torch.Tensor`): a
141 matrix of size :math:`N \times D` where :math:`N` is the number of
142 points in the :math:`D` dimensional space.
143
144 :attr:`features` (:attr:`numpy.ndarray` or :attr:`torch.Tensor`, optional): a
145 matrix of size :math:`N \times D_F` where :math:`N` is the number of
146 points and :math:`D_F` is the dimension of the features. Must have the
147 same container as `coords` (i.e. if `coords` is a torch.Tensor, `feats`
148 must also be a torch.Tensor).
149
150 :attr:`labels` (:attr:`numpy.ndarray` or :attr:`torch.IntTensor`,
151 optional): integer labels associated to eah coordinates. Must have the
152 same container as `coords` (i.e. if `coords` is a torch.Tensor,
153 `labels` must also be a torch.Tensor). For classification where a set
154 of points are mapped to one label, do not feed the labels.
155
156 :attr:`ignore_label` (:attr:`int`, optional): the int value of the
157 IGNORE LABEL.
158 :attr:`torch.nn.CrossEntropyLoss(ignore_index=ignore_label)`
159
160 :attr:`return_index` (:attr:`bool`, optional): set True if you want the
161 indices of the quantized coordinates. False by default.
162
163 :attr:`return_inverse` (:attr:`bool`, optional): set True if you want
164 the indices that can recover the discretized original coordinates.
165 False by default. `return_index` must be True when `return_reverse` is True.
166
167 :attr:`return_maps_only` (:attr:`bool`, optional): if set, return the
168 unique_map or optionally inverse map, but not the coordinates. Can be
169 used if you don't care about final coordinates or if you use
170 device==cuda and you don't need coordinates on GPU. This returns either
171 unique_map alone or (unique_map, inverse_map) if return_inverse is set.
172
173 :attr:`quantization_size` (attr:`float`, optional): if set, will use
174 the quanziation size to define the smallest distance between
175 coordinates.
176
177 :attr:`device` (attr:`str`, optional): Either 'cpu' or 'cuda'.
178
179 Example::
180
181 >>> unique_map, inverse_map = sparse_quantize(discrete_coords, return_index=True, return_inverse=True)
182 >>> unique_coords = discrete_coords[unique_map]

Callers 8

test_device2Method · 0.90
testMethod · 0.90
test_deviceMethod · 0.90
test_mappingMethod · 0.90
test_labelMethod · 0.90
test_collisionMethod · 0.90
slice_no_duplicateMethod · 0.90

Calls 2

appendMethod · 0.80
insert_and_mapMethod · 0.45

Tested by 6

test_device2Method · 0.72
test_deviceMethod · 0.72
test_mappingMethod · 0.72
test_labelMethod · 0.72
test_collisionMethod · 0.72