def __new__(cls, axes=(0, 1), fill_value=0, align=None, **kwargs): """Create a ``Pad`` operator. Parameters ---------- axes : Sequence[int], optional The padding axes. fill_value : number, optional, default=0 The constant padding value. align : Union[int, Sequence[int]], optional The size to align the padding shape. Returns ------- nvidia.dali.ops.Pad The operator. """ return ops.Pad( axes=axes, fill_value=fill_value, align=align, device=context.get_device_type(), **kwargs )
def __new__(cls, sigma=None, window_size=None, dtype=None, **kwargs): """Create a ``GaussianBlur`` operator. Parameters ---------- sigma : Union[float, Sequence[float]], optional The sigma value to gaussian kernel. window_size : Union[int, Sequence[int]], optional The window size to gaussian kernel. dtype : str, optional The output data type. Returns ------- nvidia.dali.ops.GaussianBlur The operator. """ if isinstance(dtype, six.string_types): dtype = getattr(types, dtype.upper()) return ops.GaussianBlur(sigma=sigma, window_size=window_size, dtype=dtype, device=context.get_device_type(), **kwargs)
def __new__( cls, output_type='BGR', host_memory_padding=8388608, device_memory_padding=16777216, **kwargs ): """Create a ``ImageDecoder`` operator. Parameters ---------- output_type : {'BGR', 'RGB'}, optional The output color space. host_memory_padding : int, optional, default=8388608 The number of bytes for host buffer. device_memory_padding : int, optional, default=16777216 The number of bytes for device buffer. Returns ------- nvidia.dali.ops.ImageDecoder The operator. """ if isinstance(output_type, six.string_types): output_type = getattr(types, output_type) return ops.ImageDecoder( output_type=output_type, host_memory_padding=host_memory_padding, device_memory_padding=device_memory_padding, device=context.get_device_type(mixed=True), **kwargs )
def __new__(cls, axes=(1, 0), normalized_anchor=True, normalized_shape=True, **kwargs): """Create a ``Slice`` operator. Parameters ---------- axes : Sequence[int], optional The axis to select. normalized_anchor : bool, optional, default=True Whether the begin of interval is normalized. normalized_shape : bool, optional, default=True Whether the size of interval is normalized. Returns ------- nvidia.dali.ops.Slice The operator. """ return ops.Slice(axes=axes, normalized_anchor=normalized_anchor, device=context.get_device_type(), **kwargs)
def __new__(cls, fill_value=0, interp_type='linear', keep_size=True, **kwargs): """Create a ``Rotate`` operator. Parameters ---------- fill_value : number, optional The value to fill the empty regions. interp_type : str, optional, default='linear' The interpolation method. keep_size : bool, optional, default=True Whether to keep the original image size. Returns ------ nvidia.dali.ops.Rotate The operator. """ if isinstance(interp_type, six.string_types): interp_type = getattr(types, 'INTERP_' + interp_type.upper()) return ops.Rotate(fill_value=fill_value, interp_type=interp_type, keep_size=keep_size, device=context.get_device_type(), **kwargs)
def __new__(cls, n_channels=3, fill_value=(0., 0., 0.), ratio=None, paste_x=None, paste_y=None, **kwargs): """Create a ``Paste`` operator. Parameters ---------- n_channels : int, optional, default=3 The image channels. fill_value : Sequence[number], optional The value(s) to fill for the canvas. ratio : int, optional The expand ratio. paste_x : int, optional The paste position at x-axis. paste_y : int, optional The paste position at y-axis. Returns ------- nvidia.dali.ops.Paste The operator. """ return ops.Paste(n_channels=n_channels, fill_value=fill_value, ratio=ratio, paste_x=paste_x, paste_y=paste_y, device=context.get_device_type(), **kwargs)
def __new__(cls, horizontal=None, vertical=None, depthwise=None, **kwargs): """Create a ``Flip`` operator. Parameters ---------- horizontal : int, optional Whether to apply the horizontal flip. vertical : int, optional Whether to apply the vertical flip. depthwise : bool, optional, default=True Whether to apply the depthwise flip. Returns ------- nvidia.dali.ops.Flip The operator. """ return ops.Flip( horizontal=horizontal, vertical=vertical, depthwise=depthwise, device=context.get_device_type(), **kwargs )
def __new__( cls, axes=(0, 1), fill_value=0, normalized_anchor=True, normalized_shape=True, **kwargs ): """Create an ``Erase`` operator. Parameters ---------- axes : Sequence[int], optional The padding axes. fill_value : Union[number, Sequence[float]], optional The value to fill the erased regions. normalized_anchor : bool, optional, default=True Provided anchor is normalized or not. normalized_shape : bool, optional, default=True Provided shape is normalized or not. Returns ------- nvidia.dali.ops.Erase The operator. """ return ops.Erase( axes=axes, fill_value=fill_value, normalized_anchor=normalized_anchor, normalized_shape=normalized_shape, device=context.get_device_type(), **kwargs )
def __new__(cls, **kwargs): """Create a ``ExternalSource`` operator. Returns ------- nvidia.dali.ops.ExternalSource The operator. """ return ops.ExternalSource(device=context.get_device_type(), **kwargs)
def __new__(cls, **kwargs): """Create a ``Brightness`` operator. Returns ------- nvidia.dali.ops.Brightness The operator. """ return ops.Brightness(device=context.get_device_type(), **kwargs)
def __new__(cls, **kwargs): """Create a ``Contrast`` operator. Returns ------- nvidia.dali.ops.Contrast The operator. """ return ops.Contrast(device=context.get_device_type(), **kwargs)
def __new__( cls, size, interp_type=None, mag_filter=None, min_filter=None, random_area=(0.08, 1.), random_aspect_ratio=(0.75, 1.33), num_attempts=10, **kwargs ): """Create a ``ImageDecoderRandomCrop`` operator. Parameters ---------- size : Union[int, Sequence[int]] The output image size. interp_type : str, optional The interpolation for both up and down sampling. mag_filter : str, optional, default='LINEAR' The interpolation for up sampling. min_filter : str, optional, default='TRIANGULAR' The interpolation for down sampling. random_area : Sequence[float], optional, default=(0.08, 1.) The range of scale for sampling. random_aspect_ratio : Sequence[float], optional, default=(0.75, 1.33) The range of aspect ratio for sampling. num_attempts : int, optional, default=10 The max number of sampling trails. Returns ------- nvidia.dali.ops.ImageDecoderRandomCrop The operator. """ if isinstance(interp_type, six.string_types): interp_type = getattr(types, 'INTERP_' + interp_type.upper()) if isinstance(mag_filter, six.string_types): mag_filter = getattr(types, 'INTERP_' + mag_filter.upper()) if isinstance(min_filter, six.string_types): min_filter = getattr(types, 'INTERP_' + min_filter.upper()) return ops.RandomResizedCrop( size=size, interp_type=interp_type, mag_filter=mag_filter, min_filter=min_filter, random_area=random_area, random_aspect_ratio=random_aspect_ratio, num_attempts=num_attempts, device=context.get_device_type(), **kwargs )
def __new__( cls, resize_x=None, resize_y=None, resize_shorter=None, resize_longer=None, max_size=None, interp_type=None, mag_filter=None, min_filter=None, **kwargs ): """Create a ``Resize`` operator. Parameters ---------- resize_x : int, optional The output image width. resize_y : int, optional The output image height. resize_shorter : int, optional Resize along the shorter side and limited by ``max_size``. resize_longer : int, optional Resize along the longer side. max_size : int, optional, default=0 The limited size for ``resize_shorter``. interp_type : str, optional The interpolation for both up and down sampling. mag_filter : str, optional, default='LINEAR' The interpolation for up sampling. min_filter : str, optional, default='TRIANGULAR' The interpolation for down sampling. """ if isinstance(interp_type, six.string_types): interp_type = getattr(types, 'INTERP_' + interp_type.upper()) if isinstance(mag_filter, six.string_types): mag_filter = getattr(types, 'INTERP_' + mag_filter.upper()) if isinstance(min_filter, six.string_types): min_filter = getattr(types, 'INTERP_' + min_filter.upper()) return ops.Resize( resize_x=resize_x, resize_y=resize_y, resize_shorter=resize_shorter, resize_longer=resize_longer, max_size=max_size, interp_type=interp_type, mag_filter=mag_filter, min_filter=min_filter, device=context.get_device_type(), **kwargs )
def __new__(cls, axes=(0, 1), mean=None, stddev=None, scale=1.0, shift=0.0, batch=False, epsilon=0, dtype='float32', **kwargs): """Create a ``Normalize`` operator. Parameters ---------- axes : Sequence[int], optional The axes to normalize. mean : float, optional The value to subtract. stddev : float, optional The value to divide after subtraction. scale : float, optional, default=1.0 The scale factor after normalization. shift : float, optional, default=0.0 The shift factor after normalization. batch : bool, optional, default=False Whether to compute mean and stddev across the batch. epsilon : float, optional, default=0 The value added to the computed variance. dtype : str, optional, default='float32' The output data type. Returns ------- nvidia.dali.ops.Normalize The operator. """ if isinstance(dtype, six.string_types): dtype = getattr(types, dtype.upper()) return ops.Normalize(axes=axes, mean=mean, stddev=stddev, scale=scale, shift=shift, batch=batch, epsilon=epsilon, dtype=dtype, device=context.get_device_type(), **kwargs)
def __new__( cls, crop=None, mirror=None, mean=0., std=1., dtype='float32', output_layout='NCHW', **kwargs ): """Create a ``CropMirrorNormalize`` operator. Parameters ---------- crop : Sequence[int], optional The cropped spatial dimensions for output. mirror : {0, 1}, optional Whether to apply the horizontal flip. mean : Union[float, Sequence[float]], optional The values to subtract. std : Union[float, Sequence[float]], optional The values to divide after subtraction. dtype : {'float16', 'float32'}, optional The data type of output. output_layout : {'NCHW', 'NHWC'}, optional The data format of output. Returns ------- nvidia.dali.ops.CropMirrorNormalize The operator. """ if isinstance(dtype, six.string_types): dtype = getattr(types, dtype.upper()) if isinstance(output_layout, six.string_types): output_layout = getattr(types, output_layout.upper()) return ops.CropMirrorNormalize( crop=crop, mirror=mirror, mean=mean, std=std, dtype=dtype, output_layout=output_layout, device=context.get_device_type(), **kwargs )
def __new__(cls, shape=None, **kwargs): """Create a ``Reshape`` operator. Parameters ---------- shape : Sequence[int], optional The optional output shape. Returns ------- nvidia.dali.ops.Reshape The operator. """ return ops.Reshape(shape=shape, device=context.get_device_type(), **kwargs)
def __new__( cls, output_type='BGR', host_memory_padding=8388608, device_memory_padding=16777216, random_area=(0.08, 1.), random_aspect_ratio=(0.75, 1.33), num_attempts=10, **kwargs ): """Create a ``ImageDecoderRandomCrop`` operator. Parameters ---------- output_type : {'BGR', 'RGB'}, optional The output color space. host_memory_padding : int, optional, default=8388608 The number of bytes for host buffer. device_memory_padding : int, optional, default=16777216 The number of bytes for device buffer. random_area : Sequence[float], optional, default=(0.08, 1.) The range of scale for sampling. random_aspect_ratio : Sequence[float], optional, default=(0.75, 1.33) The range of aspect ratio for sampling. num_attempts : int, optional, default=10 The max number of sampling trails. Returns ------- nvidia.dali.ops.ImageDecoderRandomCrop The operator. """ if isinstance(output_type, six.string_types): output_type = getattr(types, output_type) return ops.ImageDecoderRandomCrop( output_type=output_type, host_memory_padding=host_memory_padding, device_memory_padding=device_memory_padding, random_area=random_area, random_aspect_ratio=random_aspect_ratio, num_attempts=num_attempts, device=context.get_device_type(mixed=True), **kwargs )
def __new__(cls, dtype, **kwargs): """Create a ``Cast`` operator. Parameters ---------- dtype : str, optional The output data type. Returns ------- nvidia.dali.ops.Cast The operator. """ if isinstance(dtype, six.string_types): dtype = getattr(types, dtype.upper()) return ops.Cast(dtype=dtype, device=context.get_device_type(), **kwargs)
def __new__(cls, fill_value=0, interp_type='linear', **kwargs): """Create a ``WarpAffine`` operator. Parameters ---------- fill_value : number, optional The value to fill the empty regions. interp_type : str, optional, default='linear' The interpolation method. Returns ------ nvidia.dali.ops.WarpAffine The operator. """ if isinstance(interp_type, six.string_types): interp_type = getattr(types, 'INTERP_' + interp_type.upper()) return ops.WarpAffine(fill_value=fill_value, interp_type=interp_type, device=context.get_device_type(), **kwargs)
def __new__(cls, horizontal=None, vertical=None, ltrb=True, **kwargs): """Create a ``BbFlip`` operator. Parameters ---------- horizontal : int, optional Whether to apply the horizontal flip. vertical : int, optional Whether to apply the vertical flip. ltrb : bool, optional, default=True Indicate the bbox is ``ltrb`` or ``xywh`` format. Returns ------- nvidia.dali.ops.BbFlip The operator. """ return ops.BbFlip(horizontal=horizontal, vertical=vertical, ltrb=ltrb, device=context.get_device_type(), **kwargs)
def __new__(cls, image_type, output_type, **kwargs): """Create a ``ColorSpaceConversion`` operator. Parameters ---------- image_type : str The color space of input image. output_type : str The color space of output image. Returns ------- nvidia.dali.ops.ColorSpaceConversion The operator. """ if isinstance(image_type, six.string_types): image_type = getattr(types, image_type) if isinstance(output_type, six.string_types): output_type = getattr(types, output_type) return ops.ColorSpaceConversion(image_type=image_type, output_type=output_type, device=context.get_device_type(), **kwargs)