easycv.datasets.shared.pipelines package

Submodules

easycv.datasets.shared.pipelines.dali_transforms module

class easycv.datasets.shared.pipelines.dali_transforms.DaliImageDecoder(device='mixed', **kwargs)[source]

Bases: object

refer to: https://docs.nvidia.com/deeplearning/dali/archives/dali_0250/user-guide/docs/supported_ops.html#nvidia.dali.ops.ImageDecoder

__init__(device='mixed', **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

class easycv.datasets.shared.pipelines.dali_transforms.DaliRandomResizedCrop(size, random_area, device='gpu', **kwargs)[source]

Bases: object

refer to: https://docs.nvidia.com/deeplearning/dali/archives/dali_0250/user-guide/docs/supported_ops.html#nvidia.dali.ops.RandomResizedCrop

__init__(size, random_area, device='gpu', **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

class easycv.datasets.shared.pipelines.dali_transforms.DaliResize(resize_shorter, device='gpu', **kwargs)[source]

Bases: object

refer to: https://docs.nvidia.com/deeplearning/dali/archives/dali_0250/user-guide/docs/supported_ops.html#nvidia.dali.ops.Resize

__init__(resize_shorter, device='gpu', **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

class easycv.datasets.shared.pipelines.dali_transforms.DaliColorTwist(prob, saturation, contrast, brightness, hue, device='gpu', center=1)[source]

Bases: object

refer to: https://docs.nvidia.com/deeplearning/dali/archives/dali_0250/user-guide/docs/supported_ops.html#nvidia.dali.ops.ColorTwist

__init__(prob, saturation, contrast, brightness, hue, device='gpu', center=1)[source]

Initialize self. See help(type(self)) for accurate signature.

class easycv.datasets.shared.pipelines.dali_transforms.DaliRandomGrayscale(prob, device='gpu')[source]

Bases: object

refer to: https://docs.nvidia.com/deeplearning/dali/archives/dali_0250/user-guide/docs/supported_ops.html#nvidia.dali.ops.Hsv Create RandomGrayscale op with ops.Hsv. when saturation=0, it represents a grayscale image

__init__(prob, device='gpu')[source]

Initialize self. See help(type(self)) for accurate signature.

class easycv.datasets.shared.pipelines.dali_transforms.DaliCropMirrorNormalize(crop, mean, std, prob=0.0, device='gpu', crop_pos_x=0.5, crop_pos_y=0.5, **kwargs)[source]

Bases: object

refer to: https://docs.nvidia.com/deeplearning/dali/archives/dali_0250/user-guide/docs/supported_ops.html#nvidia.dali.ops.CropMirrorNormalize

__init__(crop, mean, std, prob=0.0, device='gpu', crop_pos_x=0.5, crop_pos_y=0.5, **kwargs)[source]

Initialize self. See help(type(self)) for accurate signature.

easycv.datasets.shared.pipelines.format module

easycv.datasets.shared.pipelines.format.to_tensor(data)[source]

Convert objects of various python types to torch.Tensor.

Supported types are: numpy.ndarray, torch.Tensor, Sequence, int and float.

Parameters

data (torch.Tensor | numpy.ndarray | Sequence | int | float) – Data to be converted.

class easycv.datasets.shared.pipelines.format.ImageToTensor(keys)[source]

Bases: object

Convert image to torch.Tensor by given keys.

The dimension order of input image is (H, W, C). The pipeline will convert it to (C, H, W). If only 2 dimension (H, W) is given, the output would be (1, H, W).

Parameters

keys (Sequence[str]) – Key of images to be converted to Tensor.

__init__(keys)[source]

Initialize self. See help(type(self)) for accurate signature.

class easycv.datasets.shared.pipelines.format.Collect(keys, meta_keys=('filename', 'ori_filename', 'ori_img_shape', 'img_shape', 'scale_factor', 'pad', 'flip', 'flip_direction', 'img_norm_cfg'))[source]

Bases: object

Collect data from the loader relevant to the specific task.

This is usually the last stage of the data loader pipeline. Typically keys is set to some subset of “img”, “proposals”, “gt_bboxes”, “gt_bboxes_ignore”, “gt_labels”, and/or “gt_masks”.

The “img_meta” item is always populated. The contents of the “img_meta” dictionary depends on “meta_keys”. By default this includes:

  • “img_shape”: shape of the image input to the network as a tuple (h, w). Note that images may be zero padded on the bottom/right if the batch tensor is larger than this shape.

  • “scale_factor”: a float indicating the preprocessing scale

  • “flip”: a boolean indicating if image flip transform was used

  • “filename”: path to the image file

  • “ori_img_shape”: original shape of the image as a tuple (h, w, c)

  • “img_norm_cfg”: a dict of normalization information:

    • mean - per channel mean subtraction

    • std - per channel std divisor

    • to_rgb - bool indicating if bgr was converted to rgb

Parameters
  • keys (Sequence[str]) – Keys of results to be collected in data.

  • meta_keys (Sequence[str], optional) –

    Meta keys to be converted to mmcv.DataContainer and collected in data[img_metas]. Default: ``(‘filename’, ‘ori_filename’, ‘ori_img_shape’, ‘img_shape’,

    ’scale_factor’, ‘flip’, ‘flip_direction’, ‘img_norm_cfg’)``

__init__(keys, meta_keys=('filename', 'ori_filename', 'ori_img_shape', 'img_shape', 'scale_factor', 'pad', 'flip', 'flip_direction', 'img_norm_cfg'))[source]

Initialize self. See help(type(self)) for accurate signature.

class easycv.datasets.shared.pipelines.format.DefaultFormatBundle[source]

Bases: object

Default formatting bundle. It simplifies the pipeline of formatting common fields, including “img”, “proposals”, “gt_bboxes”, “gt_labels”, “gt_masks” and “gt_semantic_seg”. These fields are formatted as follows. - img: (1)transpose, (2)to tensor, (3)to DataContainer (stack=True) - proposals: (1)to tensor, (2)to DataContainer - gt_bboxes: (1)to tensor, (2)to DataContainer - gt_bboxes_ignore: (1)to tensor, (2)to DataContainer - gt_labels: (1)to tensor, (2)to DataContainer - gt_masks: (1)to tensor, (2)to DataContainer (cpu_only=True) - gt_semantic_seg: (1)unsqueeze dim-0 (2)to tensor, (3)to DataContainer (stack=True)

easycv.datasets.shared.pipelines.third_transforms_wrapper module

easycv.datasets.shared.pipelines.third_transforms_wrapper.is_child_of(obj, cls)[source]
easycv.datasets.shared.pipelines.third_transforms_wrapper.get_args(obj)[source]
easycv.datasets.shared.pipelines.third_transforms_wrapper.wrap_torchvision_transforms(transform_obj)[source]
class easycv.datasets.shared.pipelines.third_transforms_wrapper.AugMix(severity: int = 3, mixture_width: int = 3, chain_depth: int = -1, alpha: float = 1.0, all_ops: bool = True, interpolation: torchvision.transforms.functional.InterpolationMode = <InterpolationMode.BILINEAR: 'bilinear'>, fill: Optional[List[float]] = None)

Bases: torchvision.transforms.autoaugment.AugMix

forward(results)

img (PIL Image or Tensor): Image to be transformed.

Returns

Transformed image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.AutoAugment(policy: torchvision.transforms.autoaugment.AutoAugmentPolicy = <AutoAugmentPolicy.IMAGENET: 'imagenet'>, interpolation: torchvision.transforms.functional.InterpolationMode = <InterpolationMode.NEAREST: 'nearest'>, fill: Optional[List[float]] = None)

Bases: torchvision.transforms.autoaugment.AutoAugment

forward(results)

img (PIL Image or Tensor): Image to be transformed.

Returns

AutoAugmented image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.CenterCrop(size)

Bases: torchvision.transforms.transforms.CenterCrop

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be cropped.

Returns

Cropped image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.ColorJitter(brightness=0, contrast=0, saturation=0, hue=0)

Bases: torchvision.transforms.transforms.ColorJitter

forward(results)
Parameters

img (PIL Image or Tensor) – Input image.

Returns

Color jittered image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.ConvertImageDtype(dtype: torch.dtype)

Bases: torchvision.transforms.transforms.ConvertImageDtype

forward(results)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.ElasticTransform(alpha=50.0, sigma=5.0, interpolation=<InterpolationMode.BILINEAR: 'bilinear'>, fill=0)

Bases: torchvision.transforms.transforms.ElasticTransform

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be transformed.

Returns

Transformed image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.FiveCrop(size)

Bases: torchvision.transforms.transforms.FiveCrop

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be cropped.

Returns

tuple of 5 images. Image can be PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.GaussianBlur(kernel_size, sigma=(0.1, 2.0))

Bases: torchvision.transforms.transforms.GaussianBlur

forward(results)
Parameters

img (PIL Image or Tensor) – image to be blurred.

Returns

Gaussian blurred image

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.Grayscale(num_output_channels=1)

Bases: torchvision.transforms.transforms.Grayscale

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be converted to grayscale.

Returns

Grayscaled image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.Lambda(lambd)

Bases: torchvision.transforms.transforms.Lambda

class easycv.datasets.shared.pipelines.third_transforms_wrapper.LinearTransformation(transformation_matrix, mean_vector)

Bases: torchvision.transforms.transforms.LinearTransformation

forward(results)
Parameters

tensor (Tensor) – Tensor image to be whitened.

Returns

Transformed image.

Return type

Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.Normalize(mean, std, inplace=False)

Bases: torchvision.transforms.transforms.Normalize

forward(results)
Parameters

tensor (Tensor) – Tensor image to be normalized.

Returns

Normalized Tensor image.

Return type

Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.PILToTensor

Bases: torchvision.transforms.transforms.PILToTensor

class easycv.datasets.shared.pipelines.third_transforms_wrapper.Pad(padding, fill=0, padding_mode='constant')

Bases: torchvision.transforms.transforms.Pad

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be padded.

Returns

Padded image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandAugment(num_ops: int = 2, magnitude: int = 9, num_magnitude_bins: int = 31, interpolation: torchvision.transforms.functional.InterpolationMode = <InterpolationMode.NEAREST: 'nearest'>, fill: Optional[List[float]] = None)

Bases: torchvision.transforms.autoaugment.RandAugment

forward(results)

img (PIL Image or Tensor): Image to be transformed.

Returns

Transformed image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomAdjustSharpness(sharpness_factor, p=0.5)

Bases: torchvision.transforms.transforms.RandomAdjustSharpness

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be sharpened.

Returns

Randomly sharpened image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomAffine(degrees, translate=None, scale=None, shear=None, interpolation=<InterpolationMode.NEAREST: 'nearest'>, fill=0, center=None)

Bases: torchvision.transforms.transforms.RandomAffine

forward(results)

img (PIL Image or Tensor): Image to be transformed.

Returns

Affine transformed image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomAutocontrast(p=0.5)

Bases: torchvision.transforms.transforms.RandomAutocontrast

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be autocontrasted.

Returns

Randomly autocontrasted image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomChoice(transforms, p=None)

Bases: torchvision.transforms.transforms.RandomChoice

class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomCrop(size, padding=None, pad_if_needed=False, fill=0, padding_mode='constant')

Bases: torchvision.transforms.transforms.RandomCrop

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be cropped.

Returns

Cropped image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomEqualize(p=0.5)

Bases: torchvision.transforms.transforms.RandomEqualize

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be equalized.

Returns

Randomly equalized image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomErasing(p=0.5, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=0, inplace=False)

Bases: torchvision.transforms.transforms.RandomErasing

forward(results)
Parameters

img (Tensor) – Tensor image to be erased.

Returns

Erased Tensor image.

Return type

img (Tensor)

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomGrayscale(p=0.1)

Bases: torchvision.transforms.transforms.RandomGrayscale

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be converted to grayscale.

Returns

Randomly grayscaled image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomHorizontalFlip(p=0.5)

Bases: torchvision.transforms.transforms.RandomHorizontalFlip

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be flipped.

Returns

Randomly flipped image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomInvert(p=0.5)

Bases: torchvision.transforms.transforms.RandomInvert

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be inverted.

Returns

Randomly color inverted image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomOrder(transforms)

Bases: torchvision.transforms.transforms.RandomOrder

class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomPerspective(distortion_scale=0.5, p=0.5, interpolation=<InterpolationMode.BILINEAR: 'bilinear'>, fill=0)

Bases: torchvision.transforms.transforms.RandomPerspective

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be Perspectively transformed.

Returns

Randomly transformed image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomPosterize(bits, p=0.5)

Bases: torchvision.transforms.transforms.RandomPosterize

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be posterized.

Returns

Randomly posterized image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomResizedCrop(size, scale=(0.08, 1.0), ratio=(0.75, 1.3333333333333333), interpolation=<InterpolationMode.BILINEAR: 'bilinear'>, antialias: Optional[bool] = None)

Bases: torchvision.transforms.transforms.RandomResizedCrop

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be cropped and resized.

Returns

Randomly cropped and resized image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomRotation(degrees, interpolation=<InterpolationMode.NEAREST: 'nearest'>, expand=False, center=None, fill=0)

Bases: torchvision.transforms.transforms.RandomRotation

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be rotated.

Returns

Rotated image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomSolarize(threshold, p=0.5)

Bases: torchvision.transforms.transforms.RandomSolarize

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be solarized.

Returns

Randomly solarized image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.RandomVerticalFlip(p=0.5)

Bases: torchvision.transforms.transforms.RandomVerticalFlip

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be flipped.

Returns

Randomly flipped image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.Resize(size, interpolation=<InterpolationMode.BILINEAR: 'bilinear'>, max_size=None, antialias=None)

Bases: torchvision.transforms.transforms.Resize

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be scaled.

Returns

Rescaled image.

Return type

PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.TenCrop(size, vertical_flip=False)

Bases: torchvision.transforms.transforms.TenCrop

forward(results)
Parameters

img (PIL Image or Tensor) – Image to be cropped.

Returns

tuple of 10 images. Image can be PIL Image or Tensor

training: bool
class easycv.datasets.shared.pipelines.third_transforms_wrapper.ToPILImage(mode=None)

Bases: torchvision.transforms.transforms.ToPILImage

class easycv.datasets.shared.pipelines.third_transforms_wrapper.ToTensor

Bases: torchvision.transforms.transforms.ToTensor

class easycv.datasets.shared.pipelines.third_transforms_wrapper.TrivialAugmentWide(num_magnitude_bins: int = 31, interpolation: torchvision.transforms.functional.InterpolationMode = <InterpolationMode.NEAREST: 'nearest'>, fill: Optional[List[float]] = None)

Bases: torchvision.transforms.autoaugment.TrivialAugmentWide

forward(results)

img (PIL Image or Tensor): Image to be transformed.

Returns

Transformed image.

Return type

PIL Image or Tensor

training: bool

easycv.datasets.shared.pipelines.transforms module

class easycv.datasets.shared.pipelines.transforms.Compose(transforms, profiling=False)[source]

Bases: object

Compose a data pipeline with a sequence of transforms. :param transforms: Either config dicts of transforms or transform objects. :type transforms: list[dict | callable]

__init__(transforms, profiling=False)[source]

Initialize self. See help(type(self)) for accurate signature.

class easycv.datasets.shared.pipelines.transforms.LoadImage(to_float32=False, mode='bgr')[source]

Bases: object

Load an image from file or numpy or PIL object. :param to_float32: Whether to convert the loaded image to a float32

numpy array. If set to False, the loaded image is an uint8 array. Defaults to False.

__init__(to_float32=False, mode='bgr')[source]

Initialize self. See help(type(self)) for accurate signature.