#4654·kornia

RandomCrop3D returns the padded volume when gated off (p=0 with padding / pad_if_needed) — 3D twin of #772

Author: ducha-aikiCreated Sep 18, 2026Updated Sep 18, 2026

Summary

A gated-off RandomCrop3D with padding or pad_if_needed returns the padded volume rather than the input. This is the 3D twin of #772, which was fixed for the 2D class.

python
import torch, kornia.augmentation as K
x = torch.arange(1, 121.).reshape(1, 1, 4, 5, 6)
K.RandomCrop3D((2, 3, 4), padding=2, p=0.)(x).shape            # (1, 1, 8, 9, 10)
K.RandomCrop3D((6, 7, 9), pad_if_needed=True, p=0.)(x).shape   # (1, 1, 8, 9, 12)
K.RandomCrop((2, 3), padding=2, p=0.)(torch.rand(1, 1, 5, 6)).shape   # (1, 1, 5, 6)  <- 2D is right

Expected

p=0 returns the input unchanged, as the 2D class does.

Measured on main @ c643312a3 merged with #4634 (docs-only), torch 2.14.0, CPU, macOS arm64. Found while reviewing #4634 (batch 6d of #4407).

Posted on behalf of @ducha-aiki by Claude (Fable 5.1).