Skip to content
class

PadIfNeeded

extends_NoParamsGeometricTransform[Empty]
PadIfNeeded(min_height: int | None = 1024, min_width: int | None = 1024, border_mode: int = 4, value: float | tuple[float, ...] = 0.0, mask_value: float = 0.0, p: float = 1.0, position: str = 'center', pad_height_divisor: int | None = None, pad_width_divisor: int | None = None)

Pad to at least min_height x min_width (Albumentations PadIfNeeded).

Parameters

min_heightint or None= 1024
Minimum output size; smaller inputs are padded up to it. None sets no minimum on that axis.
min_widthint or None= 1024
Minimum output size; smaller inputs are padded up to it. None sets no minimum on that axis.
border_modeint= 4
No description.
valuefloat or tuple of float= 0.0
Fill for the image's padded area; a tuple gives one value per channel.
mask_valuefloat= 0.0
No description.
pfloat= 1.0
No description.
positionstr= "center"
Where a smaller input sits on the padded canvas: "center", "top_left", "top_right", "bottom_left" or "bottom_right" (the Albumentations names). Boxes, masks and keypoints move with it.
pad_height_divisorint or None= None
Pad that axis further, up to the next multiple of this (the Albumentations names). None (default) leaves it at the minimum.
pad_width_divisorint or None= None
Pad that axis further, up to the next multiple of this (the Albumentations names). None (default) leaves it at the minimum.

Examples

>>> import lucid, lucid.utils.transforms as T
>>> tf = T.PadIfNeeded(64, 64, p=1.0)
>>> tuple(tf(T.Image(lucid.rand(3, 32, 32))).data.shape)
(3, 64, 64)
Pads only what is short of the target; an image already large
enough comes back untouched.  position="top_left" pads on the
bottom and right only, so the input keeps its origin.
>>> tl = T.PadIfNeeded(64, 64, position="top_left")
>>> img = lucid.rand(3, 32, 32)
>>> bool((tl(T.Image(img)).data[:, :32, :32] == img).all())
True

Used by 2

Constructors

1
dunder

__init__

→None
__init__(min_height: int | None = 1024, min_width: int | None = 1024, border_mode: int = 4, value: float | tuple[float, ...] = 0.0, mask_value: float = 0.0, p: float = 1.0, position: str = 'center', pad_height_divisor: int | None = None, pad_width_divisor: int | None = None)

Instance methods

1
fn

make_params

→Emptyfrom _NoParams
make_params(img: Tensor)

Dunder methods

1