LabelLookup#
- class voxel.LabelLookup(mapping=None)#
An ordered lookup table mapping integer label values to
Labelentries.- update(mapping) None. Update D from mapping/iterable E and F.#
If E is present and has a .keys() method, then does: for k in E.keys(): D[k] = E[k] If E is present and lacks a .keys() method, then does: for k, v in E: D[k] = v In either case, this is followed by: for k in F: D[k] = F[k]
- setdefault(key, default=None)#
Insert key with a value of default if key is not in the dictionary.
Return the value for key if key is in the dictionary, else default.
- pop(key, *args) v, remove specified key and return the corresponding value.#
If the key is not found, return the default if given; otherwise, raise a KeyError.
- popitem()#
Remove and return a (key, value) pair as a 2-tuple.
Pairs are returned in LIFO (last-in, first-out) order. Raises KeyError if the dict is empty.
- property indices_tensor: Tensor#
A cached 1D tensor of the ordered label values (keys), on the table’s device. Rebuilt automatically when the keys change.
- to(device) LabelLookup#
Return a copy of the lookup table with colors and cache on a new device.
- Parameters:
device (device) – The target device.
- Returns:
LabelLookup – The moved lookup table.
- cpu() LabelLookup#
Return a copy of the lookup table on the CPU.
- cuda() LabelLookup#
Return a copy of the lookup table on the current CUDA device.
- colors(default=(0, 0, 0)) Tensor#
Stack the label colors into an \((N, 3)\) tensor in insertion order.
- save(filename, fmt=None) None#
Save the lookup table to a file.
- Parameters:
filename (PathLike) – The path to the file to save.
fmt (str, optional) – The format of the file. If None, the format is determined by the file extension.
- classmethod load(filename, fmt=None) LabelLookup#
Load a lookup table from a file.
- Parameters:
filename (PathLike) – The path to the file to load.
fmt (str, optional) – The format of the file. If None, the format is determined by the file extension.
- Returns:
LabelLookup – The loaded lookup table.