R/item-transforms-random-geometry.R
item_transform_random_horizontal_flip.RdRandomly flips the image inside a dataset item horizontally with a given
probability. When a flip occurs, the same coordinate adjustments used by
item_transform_hflip are applied to bounding boxes and masks.
item_transform_random_horizontal_flip(x, p = 0.5)A dataset item of the same class. With probability p, the
image and targets are horizontally flipped; otherwise they are returned
unchanged.
if (FALSE) { # \dontrun{
url <- "https://upload.wikimedia.org/wikipedia/commons/b/b6/Felis_catus-cat_on_snow.jpg"
img <- base_loader(url) |> transform_to_tensor()
boxes <- torch_tensor(matrix(c(600, 200, 2880, 1860), ncol = 4), dtype = torch_float32())
before <- list(x = img, y = list(boxes = boxes, labels = "cat"))
class(before) <- c("image_with_bounding_box", "list")
after <- item_transform_random_horizontal_flip(before)
before_plot <- draw_bounding_boxes(before, colors = "blue", width = 10)
after_plot <- draw_bounding_boxes(after, colors = "red", width = 10)
tensor_image_browse(vision_make_grid(before_plot, after_plot, scale = TRUE))
} # }