pytorch / pytorch/vision

roi_align and roi_pool: Allow separate spatial scales for inputs of different height and width

Open
#7,738 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
17.9k
Forks
7.3k
Avg merge
1d 15h
Merged PRs (30d)
13

Description

🚀 The feature

It will be nice to have an option to specify separate spatial scale to perform roi_align or roi_pool for input images of different height and width (common for object detectors)

A naive way could be:

template <typename T>
__global__ void roi_align_forward_kernel_impl(
    int nthreads,
    const T* input,
    const T spatial_scale_x,
    const T spatial_scale_y,
    int channels,
    int height,
    int width,
    int pooled_height,
    int pooled_width,
    int sampling_ratio,
    bool aligned,
    const T* rois,
......
......
    T offset = aligned ? (T)0.5 : (T)0.0;
    T roi_start_w = offset_rois[1] * spatial_scale _x- offset;
    T roi_start_h = offset_rois[2] * spatial_scale_y - offset;
    T roi_end_w = offset_rois[3] * spatial_scale_x - offset;
    T roi_end_h = offset_rois[4] * spatial_scale_y - offset;

Thank you for the consideration.

Motivation, pitch

It will allow to perform feature align or pooling from features of different height and width.

Alternatives

Alternative is to custom compile these kernels with the added arguments.

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Locate the roi_align and roi_pool implementations, including roi_align_forward_kernel_impl, and trace their public entry points. Check how spatial_scale is currently passed and how tests cover these operators. Done means callers can provide independent x and y scales for inputs with different height and width, with both align and pool behavior covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
computer-vision, machine-learning
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.