Shortcuts

随机应用

class torchvision.transforms.RandomApply(transforms, p=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

Parameters:

使用 RandomApply 的示例:

变换的图示

Illustration of transforms
forward(img)[source]

定义每次调用时执行的计算。

应该由所有子类覆盖。

注意

尽管前向传递的配方需要在此函数内定义,但之后应该调用Module实例而不是这个,因为前者负责运行已注册的钩子,而后者则默默地忽略它们。