def __call__( self, input: torch.tensor, instances: torch.tensor, bounding_boxes: torch.tensor ) -> Tuple[torch.Tensor, torch.Tensor, torch.Tensor]: """ Flipping augmentation (only horizontal) :param image: (torch.Tensor) Input image of shape [channels, height, width] :param instances: (torch.Tenor) Instances segmentation maps of shape [instances, height, width] :param bounding_boxes: (torch.Tensor) Bounding boxes of shape [instances, 4 (x1, y1, x2, y2)] :return: (Tuple[torch.Tensor, torch.Tensor, torch.Tensor]) Input flipped, instances flipped & BBs flipped """ # Flip input input_flipped = input.flip(dims=(2, )) # Flip instances instances_flipped = instances.flip(dims=(2, )) # Flip bounding boxes image_center = torch.tensor((input.shape[2] // 2, input.shape[1] // 2)) bounding_boxes[:, [0, 2]] += 2 * (image_center - bounding_boxes[:, [0, 2]]) bounding_boxes_w = torch.abs(bounding_boxes[:, 0] - bounding_boxes[:, 2]) bounding_boxes[:, 0] -= bounding_boxes_w bounding_boxes[:, 2] += bounding_boxes_w return input_flipped, instances_flipped, bounding_boxes
def cummin_reversed( tensor: torch.tensor, dim: int = 0) -> torch.tensor: """Return the cumulative minimum of the elements along a given axis in inverse order. Args: tensor (torch.tensor): input tensor dim (int, optional): Defaults to 0. Axis along which the cumulative minimum is computed in inverse order Returns: max_tensor (torch.tensor): A tensor with the same size as the input holding the cumulative minimum of the input tensor. """ return cummin(tensor.flip(dim), dim).flip(dim)