RandomCrop — Torchvision 0.22 documentation (original) (raw)

class torchvision.transforms.v2.RandomCrop(size: Union[int, Sequence[int]], padding: Optional[Union[int, Sequence[int]]] = None, pad_if_needed: bool = False, fill: Union[int, float, Sequence[int], Sequence[float], None, Dict[Union[Type, str], Optional[Union[int, float, Sequence[int], Sequence[float]]]]] = 0, padding_mode: Literal['constant', 'edge', 'reflect', 'symmetric'] = 'constant')[source]

Crop the input at a random location.

If the input is a torch.Tensor or a TVTensor (e.g. Image,Video, BoundingBoxes etc.) it can have arbitrary number of leading batch dimensions. For example, the image can have [..., C, H, W] shape. A bounding box can have [..., 4] shape.

Parameters:

Examples using RandomCrop:

static get_params(img: Tensor, output_size: Tuple[int, int]) → Tuple[int, int, int, int][source]

Get parameters for crop for a random crop.

Parameters:

Returns:

params (i, j, h, w) to be passed to crop for random crop.

Return type:

tuple

make_params(flat_inputs: List[Any]) → Dict[str, Any][source]

Method to override for custom transforms.

See How to write your own v2 transforms

transform(inpt: Any, params: Dict[str, Any]) → Any[source]

Method to override for custom transforms.

See How to write your own v2 transforms