nvidia.dali.fn.per_frame

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

Marks the input tensor as a sequence.

The operator modifies the layout string of the input data to indicate that the batch contains sequences. Only the layout is affected, while the data stays untouched.

The operator can be used to feed per-frame tensor arguments when procesing sequences. For example, the following snippet shows how to apply gaussian_blur to a batch of sequences, so that a different sigma is used for each frame in each sequence:

@pipeline_def
def random_per_frame_blur():
  video, _ = fn.readers.video_resize(sequence_length=50, ...)
  sigma = fn.random.uniform(range=[0.5, 5], shape=(50,))
  blurred = fn.gaussian_blur(video, sigma=fn.per_frame(sigma))
  return blurred

Note that the outermost dimension of each tensor from a batch specified as per-frame argument must match the number of frames in the corresponding sequence processed by a given operator. For instance, in the presented example, every sequence in video batch has 50 frames, thus the shape of sigma is (50,).

Please consult documentation of a given argument of a sequence processing operator to find out if it supports per-frame input.

If the input passed to per-frame operator has no layout, a new layout is set, that starts with F and is padded with * to match dimensionality of the input. Otherwise, depending on the replace flag, the operator either checks if the first character of the layout is equal to F or replaces the character with F.

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.

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

  • replace (bool, optional, default = False) – Controls handling of the input with already specified layout. If set to False, the operator errors-out if the first character of the layout is not F. If set to True, the first character of the layout is replaced with F.

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

    Random seed.

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