From 55c95eb324b35852f9c8b922fea2ac987b0865a2 Mon Sep 17 00:00:00 2001 From: vfdev Date: Fri, 16 Oct 2020 16:27:12 +0200 Subject: [PATCH] Updated transforms docs (#2820) --- docs/source/transforms.rst | 52 +++++++++++++++++++++------- torchvision/transforms/functional.py | 2 +- torchvision/transforms/transforms.py | 22 ++++++------ 3 files changed, 51 insertions(+), 25 deletions(-) diff --git a/docs/source/transforms.rst b/docs/source/transforms.rst index 73be166e35a..517ede35dbf 100644 --- a/docs/source/transforms.rst +++ b/docs/source/transforms.rst @@ -57,77 +57,103 @@ Compositions of transforms .. autoclass:: Compose -Transforms on PIL Image ------------------------ +Transforms on PIL Image and torch.\*Tensor +------------------------------------------ .. autoclass:: CenterCrop + :members: .. autoclass:: ColorJitter + :members: .. autoclass:: FiveCrop + :members: .. autoclass:: Grayscale + :members: .. autoclass:: Pad + :members: .. autoclass:: RandomAffine + :members: .. autoclass:: RandomApply -.. autoclass:: RandomChoice - .. autoclass:: RandomCrop + :members: .. autoclass:: RandomGrayscale + :members: .. autoclass:: RandomHorizontalFlip - -.. autoclass:: RandomOrder + :members: .. autoclass:: RandomPerspective + :members: .. autoclass:: RandomResizedCrop + :members: .. autoclass:: RandomRotation + :members: .. autoclass:: RandomSizedCrop + :members: .. autoclass:: RandomVerticalFlip + :members: .. autoclass:: Resize + :members: .. autoclass:: Scale + :members: .. autoclass:: TenCrop + :members: .. autoclass:: GaussianBlur + :members: -Transforms on torch.\*Tensor +Transforms on PIL Image only ---------------------------- +.. autoclass:: RandomChoice + +.. autoclass:: RandomOrder + + +Transforms on torch.\*Tensor only +--------------------------------- + .. autoclass:: LinearTransformation + :members: .. autoclass:: Normalize - :members: __call__ - :special-members: + :members: .. autoclass:: RandomErasing + :members: + +.. autoclass:: ConvertImageDtype + Conversion Transforms --------------------- .. autoclass:: ToPILImage - :members: __call__ - :special-members: + :members: .. autoclass:: ToTensor - :members: __call__ - :special-members: + :members: + Generic Transforms ------------------ .. autoclass:: Lambda + :members: Functional Transforms diff --git a/torchvision/transforms/functional.py b/torchvision/transforms/functional.py index 1e1d048e005..13135807091 100644 --- a/torchvision/transforms/functional.py +++ b/torchvision/transforms/functional.py @@ -139,7 +139,7 @@ def convert_image_dtype(image: torch.Tensor, dtype: torch.dtype = torch.float) - dtype (torch.dtype): Desired data type of the output Returns: - (torch.Tensor): Converted image + Tensor: Converted image .. note:: diff --git a/torchvision/transforms/transforms.py b/torchvision/transforms/transforms.py index 6a7c6515790..6491ed38c20 100644 --- a/torchvision/transforms/transforms.py +++ b/torchvision/transforms/transforms.py @@ -149,7 +149,7 @@ def __init__(self, dtype: torch.dtype) -> None: super().__init__() self.dtype = dtype - def forward(self, image: torch.Tensor) -> torch.Tensor: + def forward(self, image): return F.convert_image_dtype(image, self.dtype) @@ -218,7 +218,7 @@ def __init__(self, mean, std, inplace=False): def forward(self, tensor: Tensor) -> Tensor: """ Args: - tensor (Tensor): Tensor image of size (C, H, W) to be normalized. + tensor (Tensor): Tensor image to be normalized. Returns: Tensor: Normalized Tensor image. @@ -972,7 +972,7 @@ def __init__(self, transformation_matrix, mean_vector): def forward(self, tensor: Tensor) -> Tensor: """ Args: - tensor (Tensor): Tensor image of size (C, H, W) to be whitened. + tensor (Tensor): Tensor image to be whitened. Returns: Tensor: Transformed image. @@ -1342,7 +1342,7 @@ def __init__(self, num_output_channels=1): super().__init__() self.num_output_channels = num_output_channels - def forward(self, img: Tensor) -> Tensor: + def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be converted to grayscale. @@ -1377,7 +1377,7 @@ def __init__(self, p=0.1): super().__init__() self.p = p - def forward(self, img: Tensor) -> Tensor: + def forward(self, img): """ Args: img (PIL Image or Tensor): Image to be converted to grayscale. @@ -1411,7 +1411,7 @@ class RandomErasing(torch.nn.Module): Returns: Erased Image. - # Examples: + Example: >>> transform = transforms.Compose([ >>> transforms.RandomHorizontalFlip(), >>> transforms.ToTensor(), @@ -1450,7 +1450,7 @@ def get_params( """Get parameters for ``erase`` for a random erasing. Args: - img (Tensor): Tensor image of size (C, H, W) to be erased. + img (Tensor): Tensor image to be erased. scale (tuple or list): range of proportion of erased area against input image. ratio (tuple or list): range of aspect ratio of erased area. value (list, optional): erasing value. If None, it is interpreted as "random" @@ -1487,7 +1487,7 @@ def get_params( def forward(self, img): """ Args: - img (Tensor): Tensor image of size (C, H, W) to be erased. + img (Tensor): Tensor image to be erased. Returns: img (Tensor): Erased Tensor image. @@ -1518,7 +1518,7 @@ def forward(self, img): class GaussianBlur(torch.nn.Module): """Blurs image with randomly chosen Gaussian blur. The image can be a PIL Image or a Tensor, in which case it is expected - to have [..., 3, H, W] shape, where ... means an arbitrary number of leading + to have [..., C, H, W] shape, where ... means an arbitrary number of leading dimensions Args: @@ -1554,7 +1554,7 @@ def __init__(self, kernel_size, sigma=(0.1, 2.0)): @staticmethod def get_params(sigma_min: float, sigma_max: float) -> float: - """Choose sigma for ``gaussian_blur`` for random gaussian blurring. + """Choose sigma for random gaussian blurring. Args: sigma_min (float): Minimum standard deviation that can be chosen for blurring kernel. @@ -1568,7 +1568,7 @@ def get_params(sigma_min: float, sigma_max: float) -> float: def forward(self, img: Tensor) -> Tensor: """ Args: - img (PIL Image or Tensor): image of size (C, H, W) to be blurred. + img (PIL Image or Tensor): image to be blurred. Returns: PIL Image or Tensor: Gaussian blurred image