nvidia.dali.fn.lookup_table

nvidia.dali.fn.lookup_table(__input, /, *, bytes_per_sample_hint=[0], default_value=0.0, dtype=DALIDataType.FLOAT, keys=[], preserve=False, seed=-1, values=[], device=None, name=None)

Maps the input to output by using a lookup table that is specified by keys and values, and a default_value for unspecified keys.

For example when keys and values are used to define the lookup table in the following way:

keys[] =   {0,     2,   3,   4,   5,    3}
values[] = {0.2, 0.4, 0.5, 0.6, 0.7, 0.10}
default_value = 0.99

0 <= i < max(keys)
lut[i] = values[keys.index[i]]   if i in keys
lut[i] = default_value           otherwise

the operator creates the following table:

lut[] = {0.2, 0.99, 0.4, 0.10, 0.6, 0.7}  // only last occurrence of a key is considered

and produces the output according to this formula:

Output[i] = lut[Input[i]]   if 0 <= Input[i] <= len(lut)
Output[i] = default_value   otherwise

Here is a practical example, considering the table defined above:

Input[] =  {1,      4,    1,   0,  100,   2,     3,   4}
Output[] = {0.99, 0.6, 0.99, 0.2, 0.99, 0.4,  0.10, 0.6}

Note

Only integer types can be used as inputs for this operator.

This operator allows sequence inputs and supports volumetric data.

Supported backends
  • ‘cpu’

  • ‘gpu’

Parameters:

__input (TensorList) – Input to the operator.

Keyword Arguments:
  • bytes_per_sample_hint (int or list of int, optional, default = [0]) –

    Output size hint, in bytes per sample.

    If specified, the operator’s outputs residing in GPU or page-locked host memory will be preallocated to accommodate a batch of samples of this size.

  • default_value (float, optional, default = 0.0) – Default output value for keys that are not present in the table.

  • dtype (nvidia.dali.types.DALIDataType, optional, default = DALIDataType.FLOAT) – Output data type.

  • keys (int or list of int, optional, default = []) –

    A list of input values (keys) in the lookup table.

    The length of keys and values argument must match. The values in keys should be in the [0, 65535 ] range.

  • preserve (bool, optional, default = False) – Prevents the operator from being removed from the graph even if its outputs are not used.

  • seed (int, optional, default = -1) –

    Random seed.

    If not provided, it will be populated based on the global seed of the pipeline.

  • values (float or list of float, optional, default = []) –

    A list of mapped output values for each keys entry.

    The length of the keys and the values argument must match.

  • output_dtype (nvidia.dali.types.DALIDataType) –

    Warning

    The argument output_dtype is a deprecated alias for dtype. Use dtype instead.