快捷方式

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 (sequencetorch.nn.Module) – 变换列表

  • p (float) – 应用变换列表的概率

使用 RandomApply 的示例

变换的图示

变换的图示
extra_repr() str[source]

返回模块的额外表示。

要打印自定义的额外信息,您应该在自己的模块中重新实现此方法。单行和多行字符串均可接受。

forward(*inputs: Any) Any[source]

不要覆盖此方法!请改用 transform()

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深度教程

查看教程

资源

查找开发资源并获得问题解答

查看资源