- class torchvision.transforms.v2.Compose(transforms: Sequence[Callable])¶
[BETA] Composes several transforms together.
The Compose transform is in Beta stage, and while we do not expect disruptive breaking changes, some APIs may slightly change according to user feedback. Please submit any feedback you may have in this issue: https://github.com/pytorch/vision/issues/6753.
This transform does not support torchscript. Please, see the note below.
transforms (list of
Transformobjects) – list of transforms to compose.
>>> transforms.Compose([ >>> transforms.CenterCrop(10), >>> transforms.PILToTensor(), >>> transforms.ConvertImageDtype(torch.float), >>> ])
In order to script the transformations, please use
>>> 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)
Make sure to use only scriptable transformations, i.e. that work with
torch.Tensor, does not require lambda functions or
Compose:Getting started with transforms v2Transforms v2: End-to-end object detection/segmentation exampleHow to use CutMix and MixUpHow to write your own v2 transformsTorchscript support
- extra_repr() str ¶
Set the extra representation of the module
To print customized extra information, you should re-implement this method in your own modules. Both single-line and multi-line strings are acceptable.
- forward(*inputs: Any) Any ¶
Defines the computation performed at every call.
Should be overridden by all subclasses.
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.