padding¶
- mfai.pytorch.padding.pad_batch(batch, new_shape, mode='constant', pad_value=0)[source]¶
- Given batch of 2D or 3D data and a shape new_shape,
pads the tensor with the given pad_value.
- Parameters:
batch (
Tensor) – the batch of values of shape (B, C, D, H, W) or (B, C, H, W).new_shape (
Size) – Target shape (D, H, W) for 3D tensors or (H, W) for 2D tensors to be given.mode (
Literal['constant','reflect','replicate','circular']) – the padding mode to be used. Defaults to “constant”. Same as torch.nn.functional.Padpad_value (
Optional[float]) – the padding value to be used. Defaults to 0.
- Returns:
The padded tensor.
- Return type:
Tensor
- mfai.pytorch.padding.undo_padding(batch, old_shape, inplace=False)[source]¶
Removes the padding added by pad_batch.
- Parameters:
batch (Tensor) – The padded batch of data
old_shape (torch.Size) – The original shape of the data
inplace (bool) – Whether the returned tensor is just a sliced view of the given tensor or a new copy.
- Return type: