Item transform affine - #367
Conversation
| orig_h <- as.numeric(x$x$shape[length(x$x$shape) - 1]) | ||
| orig_w <- as.numeric(x$x$shape[length(x$x$shape)]) |
There was a problem hiding this comment.
todo readability
| orig_h <- as.numeric(x$x$shape[length(x$x$shape) - 1]) | |
| orig_w <- as.numeric(x$x$shape[length(x$x$shape)]) | |
| c(orig_h, orig_w) %<-% tail(x$x$shape, 2) |
| x | ||
| } | ||
|
|
||
| affine_boxes_xyxy <- function(boxes, angle, translate, scale, shear, center, |
There was a problem hiding this comment.
todo Please rename the function into target_transform_affine.list() and move into target_transform_detection.R
todo Please document and export with the #' @family target_transforms_detection
todo Please add a generic method target_transform_affine() and a default method for proper S3 dispatch
| make_seg_item <- function(image_size = c(100L, 200L), num_masks = 3L) { | ||
| x <- torch_randn(3, image_size[1], image_size[2]) | ||
| masks <- torch_rand(num_masks, image_size[1], image_size[2]) > 0.5 | ||
| labels <- torch_ones(num_masks, dtype = torch_long()) | ||
| y <- list( | ||
| masks = masks, | ||
| labels = labels, | ||
| image_height = image_size[1], | ||
| image_width = image_size[2] | ||
| ) | ||
| item <- list(x = x, y = y) | ||
| class(item) <- c("image_with_segmentation_mask", "list") | ||
| item | ||
| } |
There was a problem hiding this comment.
todo please move this helper function into helper-torchvision.R
todo please rename it into make_segmentation_item for more transparency
There was a problem hiding this comment.
todo Please check the helper function may already be present according to #366
todo Please add a test showing affine can be composed like in
torchvision/tests/testthat/test-item-transforms-geometry.R
Lines 191 to 202 in 384aa14
todo Please note that
make_item() is now make_detection_item()
f6437af to
6904e69
Compare
cregouby
left a comment
There was a problem hiding this comment.
Praise This is a major one ! Thanks
| masks <- x$y$masks | ||
| if (!is.null(masks) && masks$ndim >= 3) { | ||
| dtype <- masks$dtype | ||
| masks <- transform_affine(masks, angle = angle, translate = translate, | ||
| scale = scale, shear = shear, | ||
| interpolation = 0, fill = fill, center = center) | ||
| x$y$masks <- masks$to(dtype = dtype) | ||
| } | ||
| x | ||
| } |
There was a problem hiding this comment.
todo Can we move that target_transform_affine.list() as well ?
thought I know this will require ugly test on the presence of parameters, waiting for #364
There was a problem hiding this comment.
todo missing can we manage also the .image_with_rotated_box() S3 class ?
6904e69 to
3830e65
Compare
cregouby
left a comment
There was a problem hiding this comment.
todo can you resolve the merge conflicts, please ?
3830e65 to
bad7f90
Compare

Closes #347.
Adds
item_transform_affine(), applying an affine transform that is rotation, translation, scale and shear to a dataset item and keeping the target aligned with the image. Follows the S3-dispatch convention from #343.