transforms#
Copyright 2025 Apple Inc.
Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
- class parameterized_transforms.transforms.CenterCrop(size: int | List[int] | Tuple[int, int], tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,CenterCrop
Creates a crop of the image at the center, with the given size. If the image size is smaller than the required crop size, the image is first padded with 0’s till the size is clear and then, it is cropped.
- Parameters:
size – The required crop size. If integer, the crop shape is [size, size]. If a list or a tuple of length 2, that is the shape of the crop. If a single element list or tuple is given, the shape is [size[0], size[0]]. Other types are not valid.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.ColorJitter(brightness: float | List[float] | Tuple[float, float] = 0, contrast: float | List[float] | Tuple[float, float] = 0, saturation: float | List[float] | Tuple[float, float] = 0, hue: float | List[float] | Tuple[float, float] = 0, tx_mode: str | TransformMode = TransformMode.CASCADE, default_params_mode: DefaultParamsMode = DefaultParamsMode.RANDOMIZED)#
Bases:
AtomicTransform
,ColorJitter
Perturbs the brightness, contrast, saturation, and hue of the given input in a random order and returns the resulting image.
- Parameters:
brightness – The amount by which to perturb the brightness. If float, the min and max amounts are set as max(0, 1 - brightness) and 1 + brightness respectively. Else, the list/tuple must be of length 2, and it is treated as the sequence of the min and the max values for the same. A uniform sample from this range is taken as the brightness factor. The value must be non-negative.
contrast – The amount by which to perturb the contrast. If float, the min and max amounts are set as max(0, 1 - contrast) and 1 + contrast respectively. Else, the list/tuple must be of length 2, and it is treated as the sequence of the min and the max values for the same. A uniform sample from this range is taken as the contrast factor. The value must be non-negative.
saturation – The amount by which to perturb the saturation. If float, the min and max amounts are set as max(0, 1 - saturation) and 1 + saturation respectively. Else, the list/tuple must be of length 2, and it is treated as the sequence of the min and the max values for the same. A uniform sample from this range is taken as the contrast factor. The value must be non-negative.
hue – The amount by which to perturb the hue. If float, the min and max amounts are set as -hue and hue respectively. Else, the list/tuple must be of length 2, and it is treated as the sequence of the min and the max values for the same. A uniform sample from this range is taken as the hue factor. The value of hue must lead to 0 <= hue <= 0.5 or -0.5 <= max <= max <= 0.5. Ensure that the image is augmented so that the pixel values are non-negative. This will not work in pixel values are negative as conversion to the HSV space fails.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
default_params_mode – The mode of the default params. SUPPORT: ptc.DefaultParamsMode.{UNIQUE,RANDOMIZED}. DEFAULT: ptc.DefaultParamsMode.RANDOMIZED.
To check the effect of the normalization to a range containing negative values, refer to the docs of tvtx.ColorJitter.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
Credits: 1. To maintain parity with pre-processing of the image data in ColorJitter transform of torchvision, we borrow code from forward method of ColorJitter class.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.Compose(transforms: Iterable[Callable], tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
ComposingTransform
,Compose
Inputs a sequence of transforms and applies each of these transforms on the given image in order to generate the augmentation.
- Parameters:
transforms – The list, tuple, or any other iterable object that can produce all the component transforms in the correct order.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_cascade_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image and corresponding augmentation parameters.
- apply_consume_transform(img: Tensor | Image, params: Tuple[int | float, ...], aug_params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Applies the transform with given parameters by consuming them.
- Parameters:
img – The data point to be augmented.
params – The parameters remaining from the augmentations so far.
aug_params – The parameters from composition of transforms.
- Returns:
The augmented image with the remaining parameters.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
Note that certain transforms can mutate the image properties and so, we obtain the default parameters and use them to keep the image mutating exactly as it would have mutated if we were carrying out the the forward pass. This ensures that all the transforms of this composition will see image with appropriate properties to decide their own default transforms.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...], aug_params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
aug_params – The processed params from the composition of transforms.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.ConvertImageDtype(dtype: dtype, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,ConvertImageDtype
Converts a torch tensor to a given data type.
- Parameters:
dtype – The data type to which to convert the input.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.ElasticTransform(image_shape: int | List[int] | Tuple[int, int], alpha: float | List[float] | Tuple[float, float] = 50.0, sigma: float | List[float] | Tuple[float, float] = 5.0, interpolation: InterpolationMode = InterpolationMode.BILINEAR, fill: float | Sequence[float] = 0.0, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,ElasticTransform
Generates a displacement field for all pixels of the image based on alpha parameter for the strength of displacements and sigma for the smoothness of displacements, and applies the field to generate elastically deformed version of the image.
- Parameters:
image_shape – The shape of the images to be processed.
alpha – The parameter to control magnitude of displacements. DEFAULT: 50.0.
sigma – The parameter to control smoothness of displacements. DEFAULT: 5.0.
interpolation – Interpolation to apply for displacing pixels. DEFAULT: tv_fn.InterpolationMode.BILINEAR.
fill – The value to fill in areas outside the transformed image. DEFAULT: 0..
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
Note that since the parametrization is the displacement field itself, we need to know the shape of the image apriori in order to define the number of parameters in this transform.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
Note that since the entire displacement field is in parameterization, we need 2 * H * W-many parameters for an image of size C x H x W.
- class parameterized_transforms.transforms.FiveCrop(size: int | List[int] | Tuple[int, int], tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,FiveCrop
Crops the image into its 4 corners and its central crops.
- Parameters:
size – The desired size of the crops. If int, the shape of the crop is [size, size]. If a sequence of length 1, the shape is [size[0], size[0]]. If a list/tuple/sequence, the length should be 2 and then, that is the shape of the crop.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.GaussianBlur(kernel_size: int | List[int] | Tuple[int, int], sigma: float | List[float] | Tuple[float, float], tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,GaussianBlur
Applies the Gaussian denoising blur to the image.
- Parameters:
kernel_size – Size of the Gaussian kernel.
sigma – The standard deviation of the Gaussian distribution to be used for the transform.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.Grayscale(num_output_channels: int = 1, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,Grayscale
Converts the input image to grayscale.
- Parameters:
num_output_channels – The number of channels in the output gray-scaled image. DEFAULT: 1
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.Lambda(lambd: Callable, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,Lambda
Implements a lambda function to enable user-defined transforms.
- Parameters:
lambd – The lambda function to be set for the transform.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.LinearTransformation(transformation_matrix: Tensor, mean_vector: Tensor, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,LinearTransformation
Applies a linear transform to the input image, which is defined as the flattening of the input data point, followed by the subtraction of the mean followed by matrix multiplication with the given matrix, followed by the reshaping to the original shape.
- Parameters:
transformation_matrix – A square matrix of the shape [D, D], where D = C*H*W, the size of the flattened image.
mean_vector – A vector of shape [D, ], with D = C*H*W.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.Normalize(mean: Tensor, std: Tensor, inplace: bool = False, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,Normalize
Normalizes the input tensors to given mean and standard deviation. This normalization is performed on a per-channel basis; check the docs of tvtx.Normalize for more details.
- Parameters:
mean – The mean with which to normalize the input tensor.
std – The standard deviation with which to normalize the input tensor.
inplace – Whether to normalize the data in-place. DEFAULT: False.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
Note that the required mean and std are intended to have n entries, where n is the number of channels in the input images. Thus, this is not a batch transform; it updates all entries in a batch with the same mean and std defined in the initializer.
- apply_transform(img: Tensor, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.PILToTensor(tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,PILToTensor
Converts a PIL-image in HWC format to a tensor in CHW format. This tensor is NOT normalized, has dtype as torch.uint8, and has values is in the range [0, 255].
- Parameters:
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.Pad(padding: int | List[int] | Tuple[int, int] | Tuple[int, int, int, int], fill: int | List[int] | Tuple[int, int] = 0, padding_mode: str = 'constant', tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,Pad
Pads the input image with a given value of padding. For the details of shape of the input data, please check the docs of tvtx.Pad.
- Parameters:
padding – The value to be padded on each of the borders. If a single int is provided, it is used to pad all borders. If a list/tuple of two values is given, it is the padding for the left/right and top/bottom borders. If a list/tuple of four values is given, it is padding for the left, top, right, bottom borders.
fill – The pixel value for the fill. DEFAULT: 0. This value is only used for constant padding mode. If it is a list/tuple of length 3, it is used as RBG values for the padding. For tensor data, only numbers are supported. For PIL images, only int or tuple values are supported.
padding_mode – The type of padding. SUPPORTS: constant, edge, reflect, symmetric. For constant, the fill value is used to pad the input. For edge, the edges of the image are extended out to pad. For reflect, the border values are reflected out into the padding. For symmetric, the padding is equivalent to repeating the image at its edge and then taking an appropriate crop. For more details, check docs of tvtx.Pad.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomAdjustSharpness(sharpness_factor: float, p: float = 0.5, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomAdjustSharpness
Adjusts the sharpness at random with given probability.
- Parameters:
sharpness_factor – The amount by which to increase the sharpness of the image. To maintain the sharpness as is, use value of 1..
p – The probability with which to apply this transform. DEFAULT: 0.5.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomAffine(degrees: float | int | List[float] | List[int] | Tuple[float, float] | Tuple[int, int], translate: Tuple[float, float] | None = None, scale: Tuple[int | float, int | float] | None = None, shear: int | float | List[int | float] | Tuple[int | float] | None = None, interpolation: InterpolationMode = InterpolationMode.NEAREST, fill: int | List[int] | Tuple = 0, center: List[int] | Tuple[int] | None = None, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomAffine
Performs a random affine transformation of the image such that the center is invariant to the transform.
- Parameters:
degrees – The range from which to choose the rotation angle. If a number is given, the range is [-degrees, degrees]. Else, the list/tuple must be of length 2, which represents the min and max angles of rotation.
translate – The tuple of FRACTIONS by which to translate the image along the width and along the height dimensions. DEFAULT: None, which means no translation.
scale – The lower and upper bounds of the factor by which to scale the image. DEFAULT: None, which means no scaling.
shear – The angle by which to shear. If a number, a shear within the range (-shear, shear) is applied along the x-axis. If a list/tuple, the length should be 2 or 4. If length 2, a shear value in range (shear[0], shear[1]) is applied to the x-axis. If length 4, a shear value in range (shear[0], shear[1]) is applied to the x-axis and a shear value in range (shear[2], shear[3]) is applied to the y-axis. DEFAULT: None, which means no shearing.
interpolation – The interpolation method to be used for image. SUPPORTS: Enum defined with tv_fn.InterpolationMode, which in turn supports the following– ‘NEAREST’, ‘BILINEAR’, ‘BICUBIC’, ‘BOX’, ‘HAMMING’, ‘LANCZOS’. DEFAULT: tv_fn.InterpolationMode.NEAREST.
fill – The fill value for the region in the output outside the rotated image. If a number, it is used to fill all channels. Otherwise, a list/tuple of the same size as the number of channels needs to be provided as the pixel value in the outside region. DEFAULT: 0.
center – The center of the rotation. DEFAULT: None. If None, then it is set to the image center.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- cascade_transform(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Implements the forward pass with dunder call.
- Parameters:
img – The data point to be augmented.
params – The previously collected parameters.
- Returns:
The augmented data point and the corresponding parameters appended to the previously collected params.
1. To maintain parity with pre-processing of the image data in RandomAffine transform of torchvision, we borrow code from forward method of RandomAffine class.
- consume_transform(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Input the data point and parameters, extract the required number of parameters, performs the required transforms, and returns the augmented data point along with remaining parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of augmented data point and remaining parameters.
1. To maintain parity with pre-processing of the image data in RandomAffine transform of torchvision, we borrow code from forward method of RandomAffine class.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomApply(transforms: Iterable[Callable], p: float = 0.5, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
ComposingTransform
,RandomApply
Randomly applies a sequence of transforms with given probability.
- Parameters:
transforms – The iterable of transforms that returns the transforms in the correct order.
p – The probability of applying this composite transform together on the input image.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_cascade_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image and corresponding augmentation parameters.
- apply_consume_transform(img: Tensor | Image, params: Tuple[int | float, ...], aug_params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Applies the transform with given parameters by consuming them.
- Parameters:
img – The data point to be augmented.
params – The parameters remaining from the augmentations so far.
aug_params – The parameters from composition of transforms.
- Returns:
The augmented image with the remaining parameters.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...], aug_params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
aug_params – The processed params from the composition of transforms.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomAutocontrast(p: float = 0.5, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomAutocontrast
Autocontrasts the given image at random with given probability.
- Parameters:
p – The probability with which to apply this transform. DEFAULT: 0.5.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomChoice(transforms: Iterable, p: Iterable | None = None, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
ComposingTransform
,RandomChoice
Apply a single transform randomly from a sequence of given transforms.
- Parameters:
transforms – An iterable of all transforms that returns the transforms in one fixed order; for instance, a list or a tuple.
p – The probabilities to weigh the choice.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_cascade_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image and corresponding augmentation parameters.
- apply_consume_transform(img: Tensor | Image, params: Tuple[int | float, ...], aug_params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Applies the transform with given parameters by consuming them.
- Parameters:
img – The data point to be augmented.
params – The parameters remaining from the augmentations so far.
aug_params – The parameters from composition of transforms.
- Returns:
The augmented image with the remaining parameters.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...], aug_params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
aug_params – The processed params from the composition of transforms.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomCrop(size: int | List[int] | Tuple[int, int], padding: int | List[int] | Tuple | None = None, pad_if_needed: bool = False, fill: int | List[int] | Tuple = 0, padding_mode: str = 'constant', tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomCrop
Crops the image at a random location. For details of image shape, please check the docs of tvtx.RandomCrop.
- Parameters:
size – The required size of the crop. If it is an int, the shape of the crop is [size, size]. If a list/tuple/iterable of length 1, the shape is [size[0], size[0]]. If a list/tuple, its length must be 2 and the shape of the crop matches size.
padding – The details to pad each border. If a single int, it is used to pad all borders. If two int`s, they are the paddings for the left/right and top/bottom borders. If four `int`s, they are the paddings for the left, top, right, bottom borders. In `TorchScript, a single int input here is not supported. Instead, used a sequence of length 1, i.e., size = 3 becomes size = [3, ]. DEFAULT: None
pad_if_needed – Pad an image if the required size is larger than the image size. Otherwise, an exception will be raised. NOTE THAT THE CROPPING WILL FOLLOW THE PADDING and so, padding at the borders of the cropped image can be different on different edges. DEFAULT: False.
fill – The value to be used to fill up the padded region. DEFAULT: 0. If the input is an int, it is set at all channels of the input. If a sequence of length 3, the three values are used to fill up the RGB channels in the padded region. This fill value is only used when the padding_mode is constant. Only tuple or int is supported for PIL images. Only numbers supported for tensors.
padding_mode – The type of padding to apply. SUPPORTS: constant, edge, reflect, symmetric. If constant, the fill value above is used to fill in the padded region. If edge, the edge pixels are padded with the last values at the edges. If reflect, the images are reflected at the edges to fill in the padded region. If symmetric, the image is tiled repeatedly and a cropped at the required size.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
For further details, check the docs of tvtx.RandomCrop.
# Here, there are 4 params– (x, y) of start and (h, w) of crop. self.param_count: int = 4
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- cascade_transform(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Input the data point and previous parameters, generate the parameters for the current transform, augment previous parameters with current parameters, and return the augmented parameters.
- Parameters:
img – The data point to be augmented.
params – The previously collected parameters.
- Returns:
The augmented data point and the corresponding parameters appended to the previously collected params.
Credits: 1. To maintain parity with pre-processing of the image data in RandomCrop transform of torchvision, we borrow code from forward method of RandomCrop class.
- consume_transform(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Input the data point and parameters, extract the required number of parameters, performs the required transforms, and returns the augmented data point along with remaining parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of augmented data point and remaining parameters.
Credits: 1. To maintain parity with pre-processing of the image data in RandomCrop transform of torchvision, we borrow code from forward method of RandomCrop class.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomEqualize(p: float = 0.5, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomEqualize
Equalizes histogram of given image at random with given probability.
- Parameters:
p – The probability with which to apply this transform. DEFAULT: 0.5.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomErasing(p: float = 0.5, scale: Tuple[float, float] | List[float] = (0.02, 0.33), ratio: Tuple[float, float] | List[float] = (0.3, 3.3), value: int | str | List[int] | Tuple[int, int, int] = 0, inplace: bool = False, tx_mode: str | TransformMode = TransformMode.CASCADE, default_params_mode: DefaultParamsMode = DefaultParamsMode.RANDOMIZED)#
Bases:
AtomicTransform
,RandomErasing
Removes a randomly selected rectangular region in the image.
- Parameters:
p – The probability with which to apply this transform.
scale – The lower and upper bounds to the proportion of the area of the rectangle to remove against the area of the image. DEFAULT: (0.02, 0.33).
ratio – The lower and upper bounds to the aspect ratio of the rectangle that needs to be removed. DEFAULT: (0.3, 3.3).
value – The value that needs to be used to fill up the removed rectangle. If int, it is used in all channels of the removed rectangle to fill. If a list/tuple of length 3, it is used to fill the three channels of the image. If the string random is used, the removed rectangle is substituted with random noise. DEFAULT: 0.
inplace – Whether to perform this transform inplace. DEFAULT: False.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
default_params_mode – The mode of the default params. SUPPORT: ptc.DefaultParamsMode.{UNIQUE,RANDOMIZED}. DEFAULT: ptc.DefaultParamsMode.RANDOMIZED.
Notes: 1. We can consider encoding fill value of random in parameterization in a unified manner as a future plan.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- cascade_transform(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Input the data point and previous parameters, generate the parameters for the current transform, augment previous parameters with current parameters, and return the augmented parameters.
- Parameters:
img – The data point to be augmented.
params – The previously collected parameters.
- Returns:
The augmented data point and the corresponding parameters appended to the previously collected params.
- consume_transform(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Input the data point and parameters, extract the required number of parameters, performs the required transforms, and returns the augmented data point along with remaining parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of augmented data point and remaining parameters.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomGrayscale(p: float = 0.1, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomGrayscale
Converts the input image to grayscale at random with given probability.
- Parameters:
p – The probability with which to convert to grayscale.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomHorizontalFlip(p: float = 0.5, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomHorizontalFlip
Flips the image horizontally at random with a given probability.
- Parameters:
p – The probability with which to flip. DEFAULT: 0.5.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomInvert(p: float = 0.5, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomInvert
Inverts the colors of the image by subtracting all pixel values from the maximum value of the pixel values. This is equivalent to img <- I - img, where I represents the max value of the pixels based on the image datatype.
- Parameters:
p – The probability with which to invert the image. DEFAULT: 0.5.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomOrder(transforms: Iterable, tx_mode: str | TransformMode = TransformMode.CASCADE, default_params_mode: DefaultParamsMode = DefaultParamsMode.RANDOMIZED)#
Bases:
ComposingTransform
,RandomOrder
Applies a sequence of given transforms but in a randomized order.
- Parameters:
transforms – The transforms to be applied in a randomized order to the input image.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
default_params_mode – The mode of the default params. SUPPORT: ptc.DefaultParamsMode.{UNIQUE,RANDOMIZED}. DEFAULT: ptc.DefaultParamsMode.RANDOMIZED.
- apply_cascade_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image and corresponding augmentation parameters.
- apply_consume_transform(img: Tensor | Image, params: Tuple[int | float, ...], aug_params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Applies the transform with given parameters by consuming them.
- Parameters:
img – The data point to be augmented.
params – The parameters remaining from the augmentations so far.
aug_params – The parameters from composition of transforms.
- Returns:
The augmented image with the remaining parameters.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...], aug_params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
aug_params – The processed params from the composition of transforms.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomPerspective(distortion_scale: float = 0.5, p: float = 0.5, interpolation: InterpolationMode = InterpolationMode.BILINEAR, fill: int | List[int] | Tuple = 0, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomPerspective
Generates a random perspective projection of the given image with a given probability.
- Parameters:
distortion_scale – The scale of image distortion. Check the docs of tvtx.RandomPerspective to track its meaning. In brief, this scale factor is used in defining the end-points of the perspective that needs to be generated.
p – The probability with which to apply this transform.
interpolation – The interpolation method to fill-in pixels. SUPPORTS: Enum defined with tv_fn.InterpolationMode, which in turn supports the following– ‘NEAREST’, ‘BILINEAR’, ‘BICUBIC’, ‘BOX’, ‘HAMMING’, ‘LANCZOS’.
fill – The fill value to be used for gaps left in perspective. If a number, it is used to fill in all channels. Else, the sequence is used to fill in the channel values.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- cascade_transform(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Input the data point and previous parameters, generate the parameters for the current transform, augment previous parameters with current parameters, and return the augmented parameters.
- Parameters:
img – The data point to be augmented.
params – The previously collected parameters.
- Returns:
The augmented data point and the corresponding parameters appended to the previously collected params.
Credits: 1. To maintain parity with pre-processing of the image data in RandomPerspective transform of torchvision, we borrow code from forward method of RandomPerspective class.
- consume_transform(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Input the data point and parameters, extract the required number of parameters, performs the required transforms, and returns the augmented data point along with remaining parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of augmented data point and remaining parameters.
Credits: 1. To maintain parity with pre-processing of the image data in RandomPerspective transform of torchvision, we borrow code from forward method of RandomPerspective class.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomPosterize(bits: int, p: float = 0.5, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomPosterize
Posterize the image by reducing the number of bits per color channel at random with a given probability.
- Parameters:
bits – The number of bits to keep per color channel (0-8).
p – The probability of applying the transform. DEFAULT: 0.5.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomResizedCrop(size: int | List[int] | Tuple[int, int], scale: List[float] | Tuple[float, float] = (0.08, 1.0), ratio: List[float] | Tuple[float, float] = (0.75, 1.3333333333333333), interpolation: InterpolationMode = InterpolationMode.BILINEAR, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomResizedCrop
Creates a randomly selected crop of the given image.
- Parameters:
size – The output size of the crop. If int, the shape of the crop is [size, size]. If it is a sequence of length 1, the shape of the crop is [size[0], size[0]]. Otherwise, it is a list or tuple, it must be of length 2, and it gives the shape of the crop.
scale – The lower and upper bounds to the ratio of the area of the crop in the original image to the area of the entire image. DEFAULT: (0.08, 1.0).
ratio – Lower and upper bounds on the aspect ratio of the crop. DEFAULT: (3.0/4.0, 4.0/3.0).
interpolation – The interpolation method to be used for crop. SUPPORTS: Enum defined with tv_fn.InterpolationMode, which in turn supports the following– ‘NEAREST’, ‘BILINEAR’, ‘BICUBIC’, ‘BOX’, ‘HAMMING’, ‘LANCZOS’. DEFAULT: tv_fn.InterpolationMode.BILINEAR.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
The parameter below seems to be added/deprecated. :deprecated antialias: Whether to use antialiasing in reshaping
images. If the input is a PIL-image, antialiasing is always used and this flag is ignored. For tensor input, the flag is False by default and needs to be set to True for BILINEAR or BICUBIC.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomRotation(degrees: float | int | List[float] | List[int] | Tuple[float, float] | Tuple[int, int], interpolation: InterpolationMode = InterpolationMode.NEAREST, expand: bool = False, center: List[int] | Tuple[int] | None = None, fill: int | List[int] | Tuple = 0, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomRotation
Rotates the image by a randomly chosen angle.
- Parameters:
degrees – The range from which to choose the rotation angle. If a number is given, the range is [-degrees, degrees]. Else, the list/tuple must be of length 2, which represents the min and max angles of rotation.
interpolation – The interpolation method to be used for image. SUPPORTS: Enum defined with tv_fn.InterpolationMode, which in turn supports the following– ‘NEAREST’, ‘BILINEAR’, ‘BICUBIC’, ‘BOX’, ‘HAMMING’, ‘LANCZOS’. DEFAULT: tv_fn.InterpolationMode.NEAREST.
expand – Whether to expand the image so that the output image holds the entire rotated image. DEFAULT: False. If False, rotated image is the same size as the input image.
center – The center of the rotation. DEFAULT: None. If None, then it is set to the image center.
fill – The fill value for the region in the output outside the rotated image. If a number, it is used to fill all channels. Otherwise, a list/tuple of the same size as the number of channels needs to be provided as the pixel value in the outside region. DEFAULT: 0.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- cascade_transform(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Input the data point and previous parameters, generate the parameters for the current transform, augment previous parameters with current parameters, and return the augmented parameters.
- Parameters:
img – The data point to be augmented.
params – The previously collected parameters.
- Returns:
The augmented data point and the corresponding parameters appended to the previously collected params.
Credits: 1. To maintain parity with pre-processing of the image data in RandomRotation transform of torchvision, we borrow code from forward method of RandomRotation class.
- consume_transform(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[Tensor | Image, Tuple[int | float, ...]] #
Input the data point and parameters, extract the required number of parameters, performs the required transforms, and returns the augmented data point along with remaining parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of augmented data point and remaining parameters.
1. To maintain parity with pre-processing of the image data in RandomRotation transform of torchvision, we borrow code from forward method of RandomRotation class.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomSolarize(threshold: float, p: float = 0.5, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomSolarize
Solarizes the image at random with a given probability.
- Parameters:
threshold – The threshold for inverting pixels; all the pixels with value equal or above this threshold will be inverted.
p – The probability with which to apply this transform. DEFAULT: 0.5.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.RandomVerticalFlip(p: float = 0.5, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,RandomVerticalFlip
Flips the image vertically at random with a given probability.
- Parameters:
p – The probability with which to flip. DEFAULT: 0.5.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.Resize(size: int | Iterable, interpolation: InterpolationMode = InterpolationMode.BILINEAR, max_size: int | None = None, antialias: bool | None = None, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,Resize
Resizes the input image to the given size.
Note that if the image is PIL-image, the interpolation uses anti-aliasing whereas the torch tensors do not. Thus, there can be a performance difference in case resizing is not done consistently. If you wish to use TorchScript on this augmentation, size should always be a list; if size is a single integer, convert it to a list of length one; i.e., size = 3 becomes size = [3, ].
- Parameters:
size – The size to which to resize to. Note that if size is an int, it is mapped to a tuple such that the smaller side of the image now becomes equal to this size.
interpolation – The interpolation method. For tensors, the supported modes are BILINEAR, NEAREST, BICUBIC.
max_size – The maximum size allowed for the longer side. If after the resize is complete, an edge is still longer than this max_size, it is rescaled again, effectively overriding size. This is only supported when size is an int or 1-long sequence.
antialias – Whether to use antialiasing. If the input is a PIL image, it is always converted with anti-alias. If the input turns out to be a tensor, this flag is False by default and needs to be explicitly set to True. This True value will only be considered for BILINEAR and BICUBIC modes, which allows to make the torch output match closer to the PIL equivalent.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.TenCrop(size: int | List[int] | Tuple[int, int], vertical_flip: bool = False, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,TenCrop
Crops the image into its 4 corners and central crop, along with the flipped versions of these 5 crops.
- Parameters:
size – The desired size of the crops. If int, the shape of the crop is [size, size]. If a sequence of length 1, the shape is [size[0], size[0]]. If a list/tuple/sequence, the length should be 2 and then, that is the shape of the crop.
vertical_flip – Whether to flip the image vertically. DEFAULT: False, as by default, the flip is horizontal.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
With probability self.p, we want to apply transform. Thus, we take a uniform sample from [0, 1] and return True or False based on the sample being smaller than or larger than self.p.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.ToPILImage(mode: str | None = None, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,ToPILImage
Converts the input tensor to a PIL image. The shape is changed from CHW format to HWC format BUT THE VALUE RANGE IS PRESERVED.
- Parameters:
mode – The mode of the input image. Please check the documentation of tvtx.ToPILImage to see its details.
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.transforms.ToTensor(tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
AtomicTransform
,ToTensor
Convert HWC-shaped, [0, 255]-ranged, and uint8 typed PIL image or numpy array into CHW-shaped [0.0, 1.0]-ranged tensor.
- Parameters:
tx_mode – The mode of the transform. DEFAULT: ptc.TransformMode.CASCADE.
- apply_transform(img: Tensor | Image, params: Tuple[int | float, ...], **kwargs) Tensor | Image #
Augments given data point using given parameters.
- Parameters:
img – The data point to be augmented.
params – The parameters to be used for augmentation.
- Returns:
The augmented image.
- extract_params(params: Tuple[int | float, ...]) Tuple[Tuple[int | float, ...], Tuple[int | float, ...]] #
Chunks the input parameters into two sets; the first required for the augmentation of the current data and the second to pass on to the next augmentations.
- Parameters:
params – The parameters remaining from the augmentations so far.
- Returns:
The tuple of the local and subsequent parameters.
- get_default_params(img: Tensor | Image, processed: bool = True) Tuple[int | float, ...] #
Returns the parameters for preserving the input data information.
- Parameters:
img – The data point to be augmented.
processed – Whether we want the processed default parameters.
- Returns:
The no-augmentation params for the class.
- get_raw_params(img: Tensor | Image) Tuple[int | float, ...] #
Generates the raw parameters used to augment current data point.
- Parameters:
img – The data point to be augmented.
- Returns:
Current raw parameters to augment the data point.
- post_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Post-processes the parameters of augmentations before outputting.
- Parameters:
img – The data point to be augmented.
params – The raw local parameters to be post-processed.
- Returns:
The post-processed parameters.
- pre_process_params(img: Tensor | Image, params: Tuple[int | float, ...]) Tuple[int | float, ...] #
Pre-processes the parameters of augmentations after inputting.
- Parameters:
img – The data point to be augmented.
params – The parameters from which to extract local parameters.
- Returns:
The pre-processed parameters ready for their usage.
- set_param_count() int #
Returns the total number of processed parameters generated by the transform under consideration.
- Returns:
The number of parameters for this transform.