def apply_hflip(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor: r"""Apply Horizontally flip on a tensor image or a batch of tensor images with given random parameters. Input should be a tensor of shape (H, W), (C, H, W) or a batch of tensors :math:`(*, C, H, W)`. Args: params (dict): A dict that must have {'batch_prob': torch.Tensor}. Can be generated from kornia.augmentation.random_generator.random_prob_generator. return_transform (bool): if ``True`` return the matrix describing the transformation applied to each input tensor. Returns: torch.Tensor: The horizontally flipped input torch.Tensor: The applied transformation matrix :math: `(*, 3, 3)` if return_transform flag is set to ``True`` """ input = _transform_input(input) _validate_input_dtype( input, accepted_dtypes=[torch.float16, torch.float32, torch.float64]) flipped: torch.Tensor = input.clone() to_flip = params['batch_prob'].to(input.device) flipped[to_flip] = hflip(input[to_flip]) return flipped
def apply_hflip(input: torch.Tensor) -> torch.Tensor: r"""Apply Horizontally flip on a tensor image or a batch of tensor images with given random parameters. Input should be a tensor of shape (H, W), (C, H, W) or a batch of tensors :math:`(B, C, H, W)`. Args: input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W). Returns: torch.Tensor: The horizontally flipped input """ return hflip(input)
def apply_hflip(input: torch.Tensor, params: Dict[str, torch.Tensor], return_transform: bool = False) -> UnionType: r"""Apply Horizontally flip on a tensor image or a batch of tensor images with given random parameters. Input should be a tensor of shape (H, W), (C, H, W) or a batch of tensors :math:`(*, C, H, W)`. Args: params (dict): A dict that must have {'batch_prob': torch.Tensor}. Can be generated from kornia.augmentation.random_generator.random_prob_generator. return_transform (bool): if ``True`` return the matrix describing the transformation applied to each input tensor. Returns: torch.Tensor: The horizontally flipped input torch.Tensor: The applied transformation matrix :math: `(*, 3, 3)` if return_transform flag is set to ``True`` """ input = _transform_input(input) _validate_input_dtype( input, accepted_dtypes=[torch.float16, torch.float32, torch.float64]) if not isinstance(return_transform, bool): raise TypeError( f"The return_transform flag must be a bool. Got {type(return_transform)}" ) flipped: torch.Tensor = input.clone() to_flip = params['batch_prob'].to(input.device) flipped[to_flip] = hflip(input[to_flip]) if return_transform: trans_mat: torch.Tensor = torch.eye(3, device=input.device, dtype=input.dtype).repeat( input.shape[0], 1, 1) w: int = input.shape[-1] flip_mat: torch.Tensor = torch.tensor([[-1, 0, w], [0, 1, 0], [0, 0, 1]]) trans_mat[to_flip] = flip_mat.type_as(input) return flipped, trans_mat return flipped
def apply_hflip(input: torch.Tensor) -> torch.Tensor: r"""Apply Horizontally flip on a tensor image or a batch of tensor images with given random parameters. Input should be a tensor of shape (H, W), (C, H, W) or a batch of tensors :math:`(B, C, H, W)`. Args: input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (B, C, H, W). Returns: torch.Tensor: The horizontally flipped input """ input = _transform_input(input) _validate_input_dtype( input, accepted_dtypes=[torch.float16, torch.float32, torch.float64]) return hflip(input)
def apply_hflip(input: torch.Tensor, params: Dict[str, torch.Tensor]) -> torch.Tensor: r"""Apply Horizontally flip on a tensor image or a batch of tensor images with given random parameters. Input should be a tensor of shape (H, W), (C, H, W) or a batch of tensors :math:`(*, C, H, W)`. Args: input (torch.Tensor): Tensor to be transformed with shape (H, W), (C, H, W), (*, C, H, W). params (Dict[str, torch.Tensor]): - params['batch_prob']: A boolean tensor thatindicating whether if to transform an image in a batch. Returns: torch.Tensor: The horizontally flipped input """ input = _transform_input(input) _validate_input_dtype(input, accepted_dtypes=[torch.float16, torch.float32, torch.float64]) flipped: torch.Tensor = input.clone() to_flip = params['batch_prob'].to(input.device) flipped[to_flip] = hflip(input[to_flip]) return flipped