wrappers#
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.wrappers.ApplyDefaultParams(transform: Callable, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
ComposingTransform
Defines a function that gets the default parameters of its transform and applies it to the image.
- Parameters:
transform – The transform to be wrapped.
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.
- 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 parameterized 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 parameterized 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 composing transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.wrappers.CastParamsToTensor(transform: Callable, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
Transform
Implements a wrappers to cast final parameters as torch.Tensor.
- Parameters:
transform – The transform to be wrapped.
tx_mode – The mode of the transform.
- 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 which needs to be augmented.
params – The parameters for the augmentations so far.
- Returns:
The tuple of augmented data point and the 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.
- 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.
- set_param_count() int #
Returns the total number of processed parameters generated by the composing transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.wrappers.DropParams(transform: Callable, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
Transform
Implements a wrappers to drop params and only output the augmented image of the underlying transform.
- Parameters:
transform – The transform to be wrapped.
tx_mode – The mode of the transform.
- cascade_transform(img: Tensor | Image, params: Tuple[int | float, ...]) Tensor | Image #
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 which needs to be augmented.
params – The parameters for the augmentations so far.
- Returns:
The tuple of augmented data point and the 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.
- 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.
- set_param_count() int #
Returns the total number of processed parameters generated by the composing transform under consideration.
- Returns:
The number of parameters for this transform.
- class parameterized_transforms.wrappers.ExtractDefaultParams(transform: Callable, tx_mode: str | TransformMode = TransformMode.CASCADE)#
Bases:
ComposingTransform
A transform that keeps the input image unchanged but exposes the default parameters of the underlying transform.
- Parameters:
transform – The transform to be wrapped.
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.
- 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 parameterized 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 parameterized 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 composing transform under consideration.
- Returns:
The number of parameters for this transform.