nvidia.dali.experimental.dynamic.readers.VideoResize#

class nvidia.dali.experimental.dynamic.readers.VideoResize(max_batch_size=None, name=None, device='cpu', num_inputs=None, *, additional_decode_surfaces=None, antialias=None, channels=None, dont_use_mmap=None, dtype=None, enable_frame_num=None, enable_timestamps=None, file_list=None, file_list_frame_num=None, file_list_include_preceding_frame=None, file_root=None, filenames=None, image_type=None, initial_fill=None, labels=None, lazy_init=None, max_size=None, minibatch_size=None, mode=None, normalized=None, num_shards=None, pad_last_batch=None, pad_sequences=None, prefetch_queue_depth=None, random_shuffle=None, read_ahead=None, roi_relative=None, seed=None, sequence_length, shard_id=None, skip_cached_images=None, skip_vfr_check=None, step=None, stick_to_shard=None, stride=None, subpixel_scale=None, temp_buffer_hint=None, tensor_init_bytes=None)#
__init__(max_batch_size=None, name=None, device='cpu', num_inputs=None, *, additional_decode_surfaces=None, antialias=None, channels=None, dont_use_mmap=None, dtype=None, enable_frame_num=None, enable_timestamps=None, file_list=None, file_list_frame_num=None, file_list_include_preceding_frame=None, file_root=None, filenames=None, image_type=None, initial_fill=None, labels=None, lazy_init=None, max_size=None, minibatch_size=None, mode=None, normalized=None, num_shards=None, pad_last_batch=None, pad_sequences=None, prefetch_queue_depth=None, random_shuffle=None, read_ahead=None, roi_relative=None, seed=None, sequence_length, shard_id=None, skip_cached_images=None, skip_vfr_check=None, step=None, stick_to_shard=None, stride=None, subpixel_scale=None, temp_buffer_hint=None, tensor_init_bytes=None)#

Loads, decodes and resizes video files with FFmpeg and NVDECODE, which is NVIDIA GPU’s hardware-accelerated video decoding.

The video streams can be in most of the container file formats. FFmpeg is used to parse video containers and returns a batch of sequences with shape (N, F, H, W, C), with N being the batch size, and F the number of frames in the sequence.

This operator combines the features of nvidia.dali.fn.video_reader() and nvidia.dali.fn.resize().

Note

The decoder supports only constant frame-rate videos.

Supported backends
  • ‘gpu’

Keyword Arguments:
  • additional_decode_surfaces (int, optional, default = 2) –

    Additional decode surfaces to use beyond minimum required.

    This argument is ignored when the decoder cannot determine the minimum number of decode surfaces

    Note

    This can happen when the driver is an older version.

    This parameter can be used to trade off memory usage with performance.

  • antialias (bool, optional, default = True) –

    If enabled, it applies an antialiasing filter when scaling down.

    Note

    Nearest neighbor interpolation does not support antialiasing.

  • channels (int, optional, default = 3) – Number of channels.

  • dont_use_mmap (bool, optional, default = False) –

    If set to True, the Loader will use plain file I/O instead of trying to map the file in memory.

    Mapping provides a small performance benefit when accessing a local file system, but most network file systems, do not provide optimum performance.

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

    Output data type.

    Supported types: UINT8 or FLOAT.

  • enable_frame_num (bool, optional, default = False) – If the file_list or filenames argument is passed, returns the frame number output.

  • enable_timestamps (bool, optional, default = False) – If the file_list or filenames argument is passed, returns the timestamps output.

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

    Path to the file with a list of file label [start_frame [end_frame]] values.

    Positive value means the exact frame, negative counts as a Nth frame from the end (it follows python array indexing schema), equal values for the start and end frame would yield an empty sequence and a warning. This option is mutually exclusive with filenames and file_root.

  • file_list_frame_num (bool, optional, default = False) –

    If the start/end timestamps are provided in file_list, you can interpret them as frame numbers instead of as timestamps.

    If floating point values have been provided, the start frame number will be rounded up and the end frame number will be rounded down.

    Frame numbers start from 0.

  • file_list_include_preceding_frame (bool, optional, default = False) –

    Changes the behavior how file_list start and end frame timestamps are translated to a frame number.

    If the start/end timestamps are provided in file_list as timestamps, the start frame is calculated as ceil(start_time_stamp * FPS) and the end as floor(end_time_stamp * FPS). If this argument is set to True, the equation changes to floor(start_time_stamp * FPS) and ceil(end_time_stamp * FPS) respectively. In effect, the first returned frame is not later, and the end frame not earlier, than the provided timestamps. This behavior is more aligned with how the visible timestamps are correlated with displayed video frames.

    Note

    When file_list_frame_num is set to True, this option does not take any effect.

    Warning

    This option is available for legacy behavior compatibility.

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

    Path to a directory that contains the data files.

    This option is mutually exclusive with filenames and file_list.

  • filenames (str or list of str, optional, default = []) –

    File names of the video files to load.

    This option is mutually exclusive with file_list and file_root.

  • image_type (nvidia.dali.types.DALIImageType, optional, default = DALIImageType.RGB) – The color space of the output frames (RGB or YCbCr).

  • initial_fill (int, optional, default = 1024) –

    Size of the buffer that is used for shuffling.

    If random_shuffle is False, this parameter is ignored.

  • labels (int or list of int, optional) –

    Labels associated with the files listed in filenames argument.

    If an empty list is provided, sequential 0-based indices are used as labels. If not provided, no labels will be yielded.

  • lazy_init (bool, optional, default = False) – Parse and prepare the dataset metadata only during the first run instead of in the constructor.

  • max_size (float or list of float, optional) –

    Limit of the output size.

    When the operator is configured to keep aspect ratio and only the smaller dimension is specified, the other(s) can grow very large. This can happen when using resize_shorter argument or “not_smaller” mode or when some extents are left unspecified.

    This parameter puts a limit to how big the output can become. This value can be specified per-axis or uniformly for all axes.

    Note

    When used with “not_smaller” mode or resize_shorter argument, max_size takes precedence and the aspect ratio is kept - for example, resizing with mode="not_smaller", size=800, max_size=1400 an image of size 1200x600 would be resized to 1400x700.

  • minibatch_size (int, optional, default = 32) – Maximum number of images that are processed in a kernel call.

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

    Resize mode.

    Here is a list of supported modes:

    • "default" - image is resized to the specified size.
      Missing extents are scaled with the average scale of the provided ones.
    • "stretch" - image is resized to the specified size.
      Missing extents are not scaled at all.
    • "not_larger" - image is resized, keeping the aspect ratio, so that no extent of the output image exceeds the specified size.
      For example, a 1280x720, with a desired output size of 640x480, actually produces a 640x360 output.
    • "not_smaller" - image is resized, keeping the aspect ratio, so that no extent of the output image is smaller than specified.
      For example, a 640x480 image with a desired output size of 1920x1080, actually produces a 1920x1440 output.

      This argument is mutually exclusive with resize_longer and resize_shorter

  • normalized (bool, optional, default = False) – Gets the output as normalized data.

  • num_shards (int, optional, default = 1) –

    Partitions the data into the specified number of parts (shards).

    This is typically used for multi-GPU or multi-node training.

  • pad_last_batch (bool, optional, default = False) –

    If set to True, pads the shard by repeating the last sample.

    Note

    If the number of batches differs across shards, this option can cause an entire batch of repeated samples to be added to the dataset.

  • pad_sequences (bool, optional, default = False) –

    Allows creation of incomplete sequences if there is an insufficient number of frames at the very end of the video.

    Redundant frames are zeroed. Corresponding time stamps and frame numbers are set to -1.

  • prefetch_queue_depth (int, optional, default = 1) –

    Specifies the number of batches to be prefetched by the internal Loader.

    This value should be increased when the pipeline is CPU-stage bound, trading memory consumption for better interleaving with the Loader thread.

  • random_shuffle (bool, optional, default = False) –

    Determines whether to randomly shuffle data.

    A prefetch buffer with a size equal to initial_fill is used to read data sequentially, and then samples are selected randomly to form a batch.

  • read_ahead (bool, optional, default = False) –

    Determines whether the accessed data should be read ahead.

    For large files such as LMDB, RecordIO, or TFRecord, this argument slows down the first access but decreases the time of all of the following accesses.

  • roi_relative (bool, optional, default = False) – If true, ROI coordinates are relative to the input size, where 0 denotes top/left and 1 denotes bottom/right

  • seed (int, optional, default = -1) – Random seed; if not set, one will be assigned automatically.

  • sequence_length (int) – Frames to load per sequence.

  • shard_id (int, optional, default = 0) – Index of the shard to read.

  • skip_cached_images (bool, optional, default = False) –

    If set to True, the loading data will be skipped when the sample is in the decoder cache.

    In this case, the output of the loader will be empty.

  • skip_vfr_check (bool, optional, default = False) –

    Skips the check for the variable frame rate (VFR) videos.

    Use this flag to suppress false positive detection of VFR videos.

    Warning

    When the dataset indeed contains VFR files, setting this flag may cause the decoder to malfunction.

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

    Frame interval between each sequence.

    When the value is less than 0, step is set to sequence_length.

  • stick_to_shard (bool, optional, default = False) –

    Determines whether the reader should stick to a data shard instead of going through the entire dataset.

    If decoder caching is used, it significantly reduces the amount of data to be cached, but might affect accuracy of the training.

  • stride (int, optional, default = 1) – Distance between consecutive frames in the sequence.

  • subpixel_scale (bool, optional, default = True) –

    If True, fractional sizes, directly specified or calculated, will cause the input ROI to be adjusted to keep the scale factor.

    Otherwise, the scale factor will be adjusted so that the source image maps to the rounded output size.

  • temp_buffer_hint (int, optional, default = 0) –

    Initial size in bytes, of a temporary buffer for resampling.

    Note

    This argument is ignored for the CPU variant.

  • tensor_init_bytes (int, optional, default = 1048576) – Hint for how much memory to allocate per image.

next_epoch(batch_size=None, ctx=None)#

Obtains an iterator that goes over the next epoch from the reader.

The return value is an iterator that returns either individual samples (if batch_size is None and was not specified at construction) or batches (if batch_size was specified here or at construction).

This iterator will go over the dataset (or shard, if sharding was specified at construction) once.

Note

The iterator must be traversed completely before the next call to next_epoch is made. Therefore, it is impossible to traverse one reader using two iterators. If another iterator is necessary, create a separate reader instance.