trw.transforms.transforms_resize_modulo_pad_crop
¶
Module Contents¶
Classes¶
Resize tensors by padding or cropping the tensor so its shape is a multiple of a |
Functions¶
|
- trw.transforms.transforms_resize_modulo_pad_crop._transform_resize_modulo_crop_pad(features_names, batch, multiple_of, mode, padding_mode, padding_constant_value)¶
- class trw.transforms.transforms_resize_modulo_pad_crop.TransformResizeModuloCropPad(multiple_of: Union[int, trw.basic_typing.ShapeX], criteria_fn: Optional[trw.transforms.transforms.CriteriaFn] = None, mode: typing_extensions.Literal[trw.transforms.crop, pad] = 'crop', padding_mode: typing_extensions.Literal[edge, constant, symmetric] = 'constant', padding_constant_value: int = 0)¶
Bases:
trw.transforms.transforms.TransformBatchWithCriteria
Resize tensors by padding or cropping the tensor so its shape is a multiple of a
multiple_of
.This can be particularly helpful in encoder-decoder architecture with skip connection which can impose constraints on the input shape (e.g., the input must be a multiple of 32 pixels).
- Parameters
multiple_of – a sequence of size len(array.shape)-2 such that shape % multiple_of == 0. To achieve this, the tensors will be padded or cropped.
criteria_fn – function applied on each feature. If satisfied, the feature will be transformed, if not the original feature is returned
padding_mode – numpy.pad mode. Currently supported are (‘constant’, ‘edge’, ‘symmetric’)
mode – one of crop, pad. If pad, the selected tensors will be padded to achieve the size tensor.shape % multiple_of == 0. If crop, the selected tensors will be cropped instead with a randomly selected cropping position.
- Returns
dictionary with the selected tensors cropped or padded to the appropriate size