Shortcuts

组合

class torchvision.transforms.Compose(transforms)[source]

将多个变换组合在一起。此变换不支持torchscript。请参阅下面的说明。

Parameters:

transforms (Transform 对象的列表) – 要组合的转换列表。

示例

>>> transforms.Compose([
>>>     transforms.CenterCrop(10),
>>>     transforms.PILToTensor(),
>>>     transforms.ConvertImageDtype(torch.float),
>>> ])

注意

为了编写转换脚本,请使用如下所示的torch.nn.Sequential

>>> transforms = torch.nn.Sequential(
>>>     transforms.CenterCrop(10),
>>>     transforms.Normalize((0.485, 0.456, 0.406), (0.229, 0.224, 0.225)),
>>> )
>>> scripted_transforms = torch.jit.script(transforms)

确保仅使用可脚本化的转换,即与torch.Tensor兼容的转换,不需要lambda函数或PIL.Image

使用 Compose 的示例:

开始使用 transforms v2

Getting started with transforms v2

Transforms v2: 端到端目标检测/分割示例

Transforms v2: End-to-end object detection/segmentation example

如何使用CutMix和MixUp

How to use CutMix and MixUp

如何编写自己的v2转换

How to write your own v2 transforms

视频API

Video API