Skip to content

Feat: Add roi_align_rotated - #36

Open
DerrickUnleashed wants to merge 20 commits into
mlverse:mainfrom
DerrickUnleashed:feat/roiAlignedRotate
Open

Feat: Add roi_align_rotated#36
DerrickUnleashed wants to merge 20 commits into
mlverse:mainfrom
DerrickUnleashed:feat/roiAlignedRotate

Conversation

@DerrickUnleashed

@DerrickUnleashed DerrickUnleashed commented Aug 2, 2026

Copy link
Copy Markdown

Adds ops_roi_align_rotated() / nn_roi_align_rotated(), a CPU RoI align pooling op for rotated boxes, ported from mmcv (Apache-2.0). Includes dispatcher + autograd kernels, R API + docs, and tests.

Closes #32

library(torch)
library(torchvision)
library(torchvisionlib)

url <- "https://upload.wikimedia.org/wikipedia/commons/b/b6/Felis_catus-cat_on_snow.jpg"
arr <- base_loader(url)                           
input <- torch_tensor(arr)$permute(c(3, 1, 2))$unsqueeze(1)     

H <- input$shape[3]/2; W <- input$shape[4]/2
rois <- torch_tensor(matrix(c(
  0, 3*W/2, 3*H/2, W, H, pi,
  0, W/2,   3*H/2, W, H, pi,
  0, 3*W/2, H/2, W, H, pi,
  0, W/2,   H/2, W, H, pi
), ncol = 6, byrow = TRUE), dtype = torch_float32())

out <- ops_roi_align_rotated(input, rois, c(128, 128), spatial_scale = 1, sampling_ratio = 2)

grid <- vision_make_grid(out, num_rows = 2, padding = 6, pad_value = 1)

tensor_image_browse(grid)     
file339407cbfb

@DerrickUnleashed
DerrickUnleashed marked this pull request as ready for review August 2, 2026 21:13
Comment thread tests/testthat/test-ops-roi-align-rotated.R Outdated
@cregouby

Copy link
Copy Markdown
Collaborator

@DerrickUnleashed ,
Could you resolve merge conflicts ?

Keep both roi_align_rotated (feature branch) and box_iou_rotated (main)
across all generated export/build/registration files.
@DerrickUnleashed

DerrickUnleashed commented Aug 17, 2026

Copy link
Copy Markdown
Author

@DerrickUnleashed , Could you resolve merge conflicts ?

Yes I have completed resolving them

The TORCH_LIBRARY_FRAGMENT schema registration was not being picked up
at runtime across shared libraries on macOS, causing
findSchemaOrThrow("torchvision::roi_align_rotated") to fail.

Bypass the PyTorch dispatcher by calling the CPU kernels and autograd
function directly instead of routing through findSchemaOrThrow.

@cregouby cregouby left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise Nice addition, clear and straightforward, thanks
todo indexing and documentation

Comment thread R/ops.R Outdated
Comment thread R/ops.R Outdated
Comment thread R/ops.R Outdated
Comment thread R/ops.R Outdated
Comment thread R/ops.R Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

implement roi_aligned_rotated

2 participants