[docs]classCompose(Transform):"""Composes several transforms together. This transform does not support torchscript. Please, see the note below. Args: transforms (list of ``Transform`` objects): list of transforms to compose. Example: >>> transforms.Compose([ >>> transforms.CenterCrop(10), >>> transforms.PILToTensor(), >>> transforms.ConvertImageDtype(torch.float), >>> ]) .. note:: In order to script the transformations, please use ``torch.nn.Sequential`` as below. >>> 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 ``PIL.Image``. """def__init__(self,transforms:Sequence[Callable])->None:super().__init__()ifnotisinstance(transforms,Sequence):raiseTypeError("Argument transforms should be a sequence of callables")elifnottransforms:raiseValueError("Pass at least one transform")self.transforms=transforms
[docs]classRandomApply(Transform):"""Apply randomly a list of transformations with a given probability. .. 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``. Args: transforms (sequence or torch.nn.Module): list of transformations p (float): probability of applying the list of transforms """_v1_transform_cls=_transforms.RandomApplydef__init__(self,transforms:Union[Sequence[Callable],nn.ModuleList],p:float=0.5)->None:super().__init__()ifnotisinstance(transforms,(Sequence,nn.ModuleList)):raiseTypeError("Argument transforms should be a sequence of callables or a `nn.ModuleList`")self.transforms=transformsifnot(0.0<=p<=1.0):raiseValueError("`p` should be a floating point value in the interval [0.0, 1.0].")self.p=pdef_extract_params_for_v1_transform(self)->Dict[str,Any]:return{"transforms":self.transforms,"p":self.p}
[docs]classRandomChoice(Transform):"""Apply single transformation randomly picked from a list. This transform does not support torchscript. Args: transforms (sequence or torch.nn.Module): list of transformations p (list of floats or None, optional): probability of each transform being picked. If ``p`` doesn't sum to 1, it is automatically normalized. If ``None`` (default), all transforms have the same probability. """def__init__(self,transforms:Sequence[Callable],p:Optional[List[float]]=None,)->None:ifnotisinstance(transforms,Sequence):raiseTypeError("Argument transforms should be a sequence of callables")ifpisNone:p=[1]*len(transforms)eliflen(p)!=len(transforms):raiseValueError(f"Length of p doesn't match the number of transforms: {len(p)} != {len(transforms)}")super().__init__()self.transforms=transformstotal=sum(p)self.p=[prob/totalforprobinp]
[docs]classRandomOrder(Transform):"""Apply a list of transformations in a random order. This transform does not support torchscript. Args: transforms (sequence or torch.nn.Module): list of transformations """def__init__(self,transforms:Sequence[Callable])->None:ifnotisinstance(transforms,Sequence):raiseTypeError("Argument transforms should be a sequence of callables")super().__init__()self.transforms=transforms
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.