快捷方式

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 的示例

變換示例

變換示例
extra_repr() str[source]

返回模組的額外表示。

為了列印自定義的額外資訊,你應當在你自己的模組中重新實現此方法。單行和多行字串均可接受。

forward(*inputs: Any) Any[source]

不要覆蓋此方法!請改用 transform()

文件

查閱 PyTorch 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得解答

檢視資源