R/target-transforms-detection.R
target_transform_resize.RdAdjusts the bounding box coordinates in a detection target to match a
resized image. The target is expected to contain a boxes field with
shape (N, 4) in xyxy format and an orig_size field with the original
image dimensions (H, W).
target_transform_resize(target, size)
# S3 method for class 'object_detection_target'
target_transform_resize(target, size)An object_detection_target, as returned by the .getitem()
method of an object detection dataset, or a bare list containing
at least:
boxes — tensor of shape (N, 4) with bounding boxes in xyxy format
orig_size — integer vector or tensor of length 2 with (height, width)
Other fields (labels, image_id, etc.) are preserved unchanged
Desired output size. If size is a integer vector of length 2
like c(h, w), output size will be matched to this. If size is a bare integer,
longest edge of the image will be matched to this number.
i.e, if height > width, then image will be rescaled to
(size * height / width, size).
A list with the same structure as the input target, where:
boxes are rescaled according to the resize factors
orig_size is updated to the new dimensions
This function should be composed with a transform_resize() in the
transform pipeline having the same size to ensure resized bounding boxes
remain aligned with the resized image.
Other target_transforms_detection:
prepare_sahi_split(),
target_transform_affine(),
target_transform_rotate()
if (FALSE) { # \dontrun{
target <- list(
boxes = torch_tensor(matrix(c(10, 20, 50, 60), ncol = 4)),
labels = torch_tensor(1L, dtype = torch_long()),
image_height = 100L,
image_width = 100L
)
class(target) <- c("object_detection_target", "list")
# Resize to fixed size
transform_fn <- target_transform_resize(c(200L, 200L))
new_target <- transform_fn(target)
# Resize with proportional scaling
transform_fn <- target_transform_resize(50L)
new_target <- transform_fn(target)
} # }