nvidia.dali.fn.experimental.decoders.image_random_crop#
- nvidia.dali.fn.experimental.decoders.image_random_crop(
- __input,
- /,
- *,
- adjust_orientation=True,
- affine=True,
- bytes_per_sample_hint=[0],
- device_memory_padding=16777216,
- device_memory_padding_jpeg2k=0,
- dtype=DALIDataType.UINT8,
- host_memory_padding=8388608,
- host_memory_padding_jpeg2k=0,
- hw_decoder_load=0.9,
- hybrid_huffman_threshold=1000000,
- jpeg_fancy_upsampling=False,
- num_attempts=10,
- output_type=DALIImageType.RGB,
- preallocate_height_hint=0,
- preallocate_width_hint=0,
- preserve=False,
- random_area=[0.08, 1.0],
- random_aspect_ratio=[0.75, 1.333333],
- seed=-1,
- use_fast_idct=False,
- device=None,
- name=None,
Decodes images and randomly crops them.
Supported formats: JPEG, JPEG 2000, TIFF, PNG, BMP, PNM, PPM, PGM, PBM, WebP.
The output of the decoder is in HWC layout.
The implementation uses NVIDIA nvImageCodec to decode images. You need to install it separately. See https://developer.nvidia.com/nvimgcodec-downloads or simply do pip install nvidia-nvimgcodec-cu${CUDA_MAJOR_VERSION} where CUDA_MAJOR_VERSION is your CUDA major version (e.g. 12).
The cropping window’s area (relative to the entire image) and aspect ratio can be restricted to a range of values specified by
area
andaspect_ratio
arguments, respectively.When possible, the operator uses the ROI decoding, reducing the decoding time and memory consumption.
Note
GPU accelerated decoding is only available for a subset of the image formats (JPEG, and JPEG2000). For other formats, a CPU based decoder is used. For JPEG, a dedicated HW decoder will be used when available.
Note
WebP decoding currently only supports the simple file format (lossy and lossless compression). For details on the different WebP file formats, see https://developers.google.com/speed/webp/docs/riff_container
- Supported backends
‘cpu’
‘mixed’
- Parameters:
__input (TensorList) – Input to the operator.
- Keyword Arguments:
adjust_orientation (bool, optional, default = True) – Use EXIF orientation metadata to rectify the images
affine (bool, optional, default = True) –
Applies only to the
mixed
backend type.If set to True, each thread in the internal thread pool will be tied to a specific CPU core. Otherwise, the threads can be reassigned to any CPU core by the operating system.
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.
device_memory_padding (int, optional, default = 16777216) –
Applies only to the
mixed
backend type.The padding for nvJPEG’s device memory allocations, in bytes. This parameter helps to avoid reallocation in nvJPEG when a larger image is encountered, and the internal buffer needs to be reallocated to decode the image.
If a value greater than 0 is provided, the operator preallocates one device buffer of the requested size per thread. If the value is correctly selected, no additional allocations will occur during the pipeline execution.
device_memory_padding_jpeg2k (int, optional, default = 0) –
Applies only to the
mixed
backend type.The padding for nvJPEG2k’s device memory allocations, in bytes. This parameter helps to avoid reallocation in nvJPEG2k when a larger image is encountered, and the internal buffer needs to be reallocated to decode the image.
If a value greater than 0 is provided, the operator preallocates the necessary number of buffers according to the hint provided. If the value is correctly selected, no additional allocations will occur during the pipeline execution.
dtype (
nvidia.dali.types.DALIDataType
, optional, default = DALIDataType.UINT8) –Output data type of the image.
Values will be converted to the dynamic range of the requested type.
host_memory_padding (int, optional, default = 8388608) –
Applies only to the
mixed
backend type.The padding for nvJPEG’s host memory allocations, in bytes. This parameter helps to prevent the reallocation in nvJPEG when a larger image is encountered, and the internal buffer needs to be reallocated to decode the image.
If a value greater than 0 is provided, the operator preallocates two (because of double-buffering) host-pinned buffers of the requested size per thread. If selected correctly, no additional allocations will occur during the pipeline execution.
host_memory_padding_jpeg2k (int, optional, default = 0) –
Applies only to the
mixed
backend type.The padding for nvJPEG2k’s host memory allocations, in bytes. This parameter helps to prevent the reallocation in nvJPEG2k when a larger image is encountered, and the internal buffer needs to be reallocated to decode the image.
If a value greater than 0 is provided, the operator preallocates the necessary number of buffers according to the hint provided. If the value is correctly selected, no additional allocations will occur during the pipeline execution.
hw_decoder_load (float, optional, default = 0.9) –
The percentage of the image data to be processed by the HW JPEG decoder.
Applies only to the
mixed
backend type in NVIDIA Ampere GPU architecture.Determines the percentage of the workload that will be offloaded to the hardware decoder, if available. The optimal workload depends on the number of threads that are provided to the DALI pipeline and should be found empirically. More details can be found at https://developer.nvidia.com/blog/loading-data-fast-with-dali-and-new-jpeg-decoder-in-a100
hybrid_huffman_threshold (int, optional, default = 1000000) –
Applies only to the
mixed
backend type.Images with a total number of pixels (
height * width
) that is higher than this threshold will use the nvJPEG hybrid Huffman decoder. Images that have fewer pixels will use the nvJPEG host-side Huffman decoder.Note
Hybrid Huffman decoder still largely uses the CPU.
jpeg_fancy_upsampling (bool, optional, default = False) –
Make the
mixed
backend use the same chroma upsampling approach as thecpu
one.The option corresponds to the JPEG fancy upsampling available in libjpegturbo or ImageMagick.
memory_stats
- num_attemptsint, optional, default = 10
Maximum number of attempts used to choose random area and aspect ratio.
- output_type
nvidia.dali.types.DALIImageType
, optional, default = DALIImageType.RGB The color space of the output image.
Note: When decoding to YCbCr, the image will be decoded to RGB and then converted to YCbCr, following the YCbCr definition from ITU-R BT.601.
- preallocate_height_hintint, optional, default = 0
Image width hint.
Applies only to the
mixed
backend type in NVIDIA Ampere GPU architecture.The hint is used to preallocate memory for the HW JPEG decoder.
- preallocate_width_hintint, optional, default = 0
Image width hint.
Applies only to the
mixed
backend type in NVIDIA Ampere GPU architecture.The hint is used to preallocate memory for the HW JPEG decoder.
- preservebool, optional, default = False
Prevents the operator from being removed from the graph even if its outputs are not used.
- random_areafloat or list of float, optional, default = [0.08, 1.0]
Range from which to choose random area fraction
A
.The cropped image’s area will be equal to
A
* original image’s area.- random_aspect_ratiofloat or list of float, optional, default = [0.75, 1.333333]
Range from which to choose random aspect ratio (width/height).
- seedint, optional, default = -1
Random seed.
If not provided, it will be populated based on the global seed of the pipeline.
split_stages : bool, optional, default = False
Warning
The argument
split_stages
is now deprecated and its usage is discouraged.use_chunk_allocator : bool, optional, default = False
Warning
The argument
use_chunk_allocator
is now deprecated and its usage is discouraged.- use_fast_idctbool, optional, default = False
Enables fast IDCT in the libjpeg-turbo based CPU decoder, used when
device
is set to “cpu” or when the it is set to “mixed” but the particular image can not be handled by the GPU implementation.According to the libjpeg-turbo documentation, decompression performance is improved by up to 14% with little reduction in quality.