RandomApply¶
- class torchvision.transforms.v2.RandomApply(transforms: Union[Sequence[Callable], ModuleList], p: float = 0.5)[source]¶
以給定的機率隨機應用轉換列表。
注意
為了編寫轉換腳本,請使用
torch.nn.ModuleList
作為輸入,而不是如下所示的轉換列表/元組>>> transforms = transforms.RandomApply(torch.nn.ModuleList([ >>> transforms.ColorJitter(), >>> ]), p=0.3) >>> scripted_transforms = torch.jit.script(transforms)
請確保僅使用可編寫腳本的轉換,即適用於
torch.Tensor
,不需要 lambda 函數或PIL.Image
。- 參數:
transforms (sequence 或 torch.nn.Module) – 轉換列表
p (float) – 應用轉換列表的機率
使用
RandomApply
的範例