Ejemplo n.º 1
0
    def test_invert(self):
        tf = T.RandomApply(
            transforms=[T.Identity(), T.ToTensor()],
            p=1,
        )

        img_tensor = tf(self.img_pil)
        self.assertIsInstance(img_tensor, torch.Tensor)
        self.assertIsInstance(tf.invert(img_tensor), Image.Image)
Ejemplo n.º 2
0
    def __call__(self, img):
        """
        Args:
            img (PIL Image): Image to be flipped.

        Returns:
            PIL Image: Randomly flipped image.
        """
        self._transform = T.Identity()
        if flip_coin(self.p):
            self._transform = HorizontalFlip()
        return self._transform(img)
Ejemplo n.º 3
0
    def __call__(self, img):
        """
        Args:
            img (PIL Image): Image to be converted to grayscale.

        Returns:
            PIL Image: Randomly grayscaled image.
        """
        self._transform = T.Identity()
        if flip_coin(self.p):
            num_output_channels = 1 if img.mode == 'L' else 3
            self._transform = Grayscale(num_output_channels=num_output_channels)
        return self._transform(img)
Ejemplo n.º 4
0
    def __call__(self, img):
        """
        Args:
            img (Tensor): Tensor image of size (C, H, W) to be erased.

        Returns:
            img (Tensor): Erased Tensor image.
        """
        self._transform = T.Identity()
        if flip_coin(self.p):
            x, y, h, w, v = self.get_params(img, scale=self.scale, ratio=self.ratio, value=self.value)
            self._transform = T.Lambda(
                lambd=lambda img: F.erase(img, x, y, h, w, v, self.inplace),
                tf_inv=lambda img: img,
                repr_str='RandomErasing()'
            )
        return img
Ejemplo n.º 5
0
    def __call__(self, img):
        """
        Args:
            img (PIL Image): Image to be Perspectively transformed.

        Returns:
            PIL Image: Random perspectivley transformed image.
        """
        self._transform = T.Identity()
        if flip_coin(self.p):
            width, height = img.size
            startpoints, endpoints = self.get_params(width, height, self.distortion_scale)
            self._transform = Perspective(
                startpoints=startpoints,
                endpoints=endpoints,
                interpolation=self.interpolation,
            )
        return self._transform(img)
Ejemplo n.º 6
0
 def setUp(self) -> None:
     super().setUp()
     self.tf = T.Identity()
Ejemplo n.º 7
0
    def __call__(self, img):

        self._transform = T.Identity()
        if flip_coin(self.p):
            self._transform = Compose(self.transforms)
        return self._transform(img)