nvidia.dali.fn.constant

nvidia.dali.fn.constant(*inputs, **kwargs)

Produces a batch of constant tensors.

The floating point input data should be placed in the fdata argument and integer data in idata. The data, which can be a flat vector of values or a scalar, is then reshaped according to the shape argument. If the data is scalar, it will be broadcast to fill the entire shape.

The operator only performs meaningful work at first invocation; subsequent calls will return a reference to the same memory.

The operator can be automatically instantiated in Python with a call to types.Constant(value, dtype, shape, layout). The value can be a scalar, a tuple, a list, or a numpy array. If not explicitly overridden, the shape and dtype, will be taken from the array.

Warning

64-bit integer and double precision arrays are not supported and will be silently downgraded to 32-bit.

Supported backends
  • ‘cpu’

  • ‘gpu’

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.

  • dtype (nvidia.dali.types.DALIDataType, optional) –

    Output data type.

    If this value is not set, the output is float if the fdata argument is used and int if idata is used.

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

    Contents of the constant that is produced (for floating point types).

    Note

    fdata and idata are mutually exclusive, and one of them is required.

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

    Contents of the constant that is produced (for integer point types).

    Note

    fdata and idata are mutually exclusive, and one of them is required.

  • layout (layout str, optional, default = ‘’) –

    Layout info.

    If set and not empty, the layout must match the dimensionality of the output.

  • 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.

  • shape (int or list of int, optional, default = []) – The desired shape of the output. If not set, the data is assumed to be 1D