Table of Contents
Shortcuts

# RandomApply

class torchvision.transforms.v2.RandomApply(transforms: Union[Sequence[Callable], ModuleList], p: float = 0.5)

  [BETA] Apply randomly a list of transformations with a given probability.

  Note

  The RandomApply 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.

  Note

  In order to script the transformation, please use `torch.nn.ModuleList` as input instead of list/tuple of transforms as shown below:

      >>> transforms = transforms.RandomApply(torch.nn.ModuleList([
      >>>     transforms.ColorJitter(),
      >>> ]), p=0.3)
      >>> 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 `PIL.Image`.

  Parameters:

    - transforms (sequence or torch.nn.Module) – list of transformations

    - p (float) – probability of applying the list of transforms

  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.

    Note

    Although the recipe for forward pass needs to be defined within this function, one should call the `Module` instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

## Docs

Access comprehensive developer documentation for PyTorch

View Docs

## Tutorials

Get in-depth tutorials for beginners and advanced developers

View Tutorials

## Resources

Find development resources and get your questions answered

View Resources

To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. As the current maintainers of this site, Facebook’s Cookies Policy applies. Learn more, including about available controls: Cookies Policy.