RandomPerspective¶
- class torchvision.transforms.v2.RandomPerspective(distortion_scale: float = 0.5, p: float = 0.5, interpolation: Union[InterpolationMode, int] = InterpolationMode.BILINEAR, fill: Union[int, float, Sequence[int], Sequence[float], None, dict[Union[type, str], Union[int, float, collections.abc.Sequence[int], collections.abc.Sequence[float], NoneType]] = 0)[原始碼]¶
以給定機率對輸入執行隨機透視變換。
如果輸入是
torch.Tensor或TVTensor(例如Image、Video、BoundingBoxes等),它可以具有任意數量的前置批處理維度。例如,影像可以具有[..., C, H, W]形狀。邊界框可以具有[..., 4]形狀。- 引數:
distortion_scale (float, optional) – 控制失真程度的引數,範圍從 0 到 1。預設為 0.5。
p (float, optional) – 輸入被變換的機率。預設為 0.5。
interpolation (InterpolationMode, optional) – 由
torchvision.transforms.InterpolationMode定義的所需插值列舉。預設為InterpolationMode.BILINEAR。如果輸入是 Tensor,則僅支援InterpolationMode.NEAREST、InterpolationMode.BILINEAR。也接受相應的 Pillow 整數常量,例如PIL.Image.BILINEAR。fill (number or tuple or dict, optional) – 當
padding_mode為 constant 時使用的畫素填充值。預設為 0。如果為長度為 3 的元組,則分別用於填充 R、G、B 通道。填充值也可以是對映資料型別到填充值的字典,例如fill={tv_tensors.Image: 127, tv_tensors.Mask: 0},其中Image將被填充為 127,Mask將被填充為 0。
使用
RandomPerspective的示例