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 or torch.nn.Module) – 变换列表
p (float) – 应用该变换列表的概率
使用
RandomApply
的示例