Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can you explain the ROIAlignLayer? #10

Open
cicelyli opened this issue Apr 12, 2018 · 0 comments
Open

Can you explain the ROIAlignLayer? #10

cicelyli opened this issue Apr 12, 2018 · 0 comments

Comments

@cicelyli
Copy link

Hi, I was trying to read the source code of ROIAlignLayer.cpp and had some difficulties understanding the bilinear interpolation part in your implementation as following.

          for (int h_idx = floor(hstart); h_idx <= ceil(hend) && h_idx < height_; ++h_idx) {
            for (int w_idx = floor(wstart); w_idx <= ceil(wend) && w_idx < width_; ++w_idx) {
              if (counter < 4) {
                b_index[counter] = ((((n*channels_ + c) * height_) + h_idx ) * width_ )+ w_idx; 
                b_index_curr[counter] = (h_idx*width_) + w_idx; 
                //Normalize h_idx and w_idx
                h_idx_n =  static_cast<Dtype>( (2*(static_cast<Dtype>(h_idx) - roi_start_h) / (roi_end_h - roi_start_h)) - 1);
                w_idx_n =  static_cast<Dtype>( (2*(static_cast<Dtype>(w_idx) - roi_start_w) / (roi_end_w - roi_start_w))  - 1);
                h_idx_n = min(max(h_idx_n, static_cast<Dtype>(-1.0)),one);
                w_idx_n = min(max(w_idx_n, static_cast<Dtype>(-1.0)),one);
                multiplier[counter] = max(zero,static_cast<Dtype>(1 - fabs(x_smp_n - w_idx_n))) 
                                         * max(zero,static_cast<Dtype>(1 - fabs(y_smp_n - h_idx_n)));

                bisampled[smp/2] += batch_data[b_index_curr[counter]]*multiplier[counter];  
                ++counter; 
	 } else { 
	    goto stop;  
	 }
            } // w_idx
          } //h_idx

Suppose if a ROI bin's width ranges from 0.5 to 2.1, and height ranges from 0.9 to 1.5. Then the hstart=0.9, hend=1.5, wstart=0.5, wend =2.1. And suppose smp = 0.

Then the loop starts with h_idx = floor(0.9) = 0, w_idx =floor(0.5) = 0, bisampled[0] is added with the feature map value at (0,0) multiplying a weight. count = 1.

In the second loop, h_idx = 0, ++w_idx =1, bisampled[0] is added with the feature map value at (0,1) multiplying a bilinear interpolation weight, count = 2

In the third loop, h_idx = 0, ++w_idx =2, bisampled[0] is added with the feature map value at (0,2) multiplying a bilinear interpolation weight. count = 3

In the fourth loop, h_idx = 0, ++w_idx =3, bisampled[0] is added with the feature map value at (0,3) multiplying a bilinear interpolation weight. count =4, then it goes to stop function.

My question is, to get the bisampled[0], isn't it to sum up the bilinear interpolation weighted feature map value at (0,0), (0,1),(1,0) and (1,1) since the upper-left corner of the ROI bin is at (0.9,0.5)? Or is there anything I misunderstood? Hope you can answer my question. Thanks!

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

No branches or pull requests

1 participant