def __call__(self, img):
        """
        Args:
            img (Tensor): Tensor image of size (C, H, W).
        Returns:
            Tensor: Image with n_holes of dimension length x length cut out of it.
        """
        h_img, w_img = img.size(1), img.size(2)
        mask = np.ones((h_img, w_img), np.float32)
        y_img = np.random.randint(h_img)
        x_img = np.random.randint(w_img)

        y1_img = np.clip(y_img - self.length // 2, 0, h_img)
        y2_img = np.clip(y_img + self.length // 2, 0, h_img)
        x1_img = np.clip(x_img - self.length // 2, 0, w_img)
        x2_img = np.clip(x_img + self.length // 2, 0, w_img)

        mask[y1_img:y2_img, x1_img:x2_img] = 0.0
        mask = torch.from_numpy(mask)
        mask = mask.expand_as(img)
        img *= mask
        return img
def __call__ ( self , img ) : h_img , w_img = img . size ( 1 ) , img . size ( 2 ) mask = np . ones ( ( h_img , w_img ) , np . float32 ) y_img = np . random . randint ( h_img ) x_img = np . random . randint ( w_img ) y1_img = np . clip ( y_img - self . length // 2 , 0 , h_img ) y2_img = np . clip ( y_img + self . length // 2 , 0 , h_img ) x1_img = np . clip ( x_img - self . length // 2 , 0 , w_img ) x2_img = np . clip ( x_img + self . length // 2 , 0 , w_img ) mask [ y1_img : y2_img , x1_img : x2_img ] = 0.0 mask = torch . from_numpy ( mask ) mask = mask . expand_as ( img ) img *= mask return img
Args:
            img (Tensor): Tensor image of size (C, H, W).
        Returns:
            Tensor: Image with n_holes of dimension length x length cut out of it.