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

CropAndResize seems to have wrong outputs #36

Open
littlespray opened this issue Feb 7, 2020 · 0 comments
Open

CropAndResize seems to have wrong outputs #36

littlespray opened this issue Feb 7, 2020 · 0 comments

Comments

@littlespray
Copy link

littlespray commented Feb 7, 2020

Hi,

I am a pytorch beginner. Recently I am trying to implement the ROIAlign in PyTorch with CropAndResize and torch.nn.functional.max_pool2d . But the output is different from torchvision.ops.RoIAlign.

code:

import torch
import torch.nn.functional as F
from torchvision.ops import RoIAlign
from my_roi_align import CropAndResize # I rename the folder as I encountered issures#32


output_size = (3,3)
spatial_scale = 1/4 
sampling_ratio = 2 

x = torch.randn(1, 1, 6, 6)
rois = torch.tensor([[0,1.0,6.6,6.7,10.1]])

x1, y1 = rois[:,1::4] * spatial_scale, rois[:,2::4] * spatial_scale
x2, y2 = rois[:,3::4] * spatial_scale, rois[:,4::4] * spatial_scale
H, W = x.shape[2], x.shape[3]

ya = RoIAlign(output_size, spatial_scale=spatial_scale, sampling_ratio=sampling_ratio)(x, rois)
yb = CropAndResize(sampling_ratio*output_size[1], sampling_ratio*output_size[0])(x, torch.cat([y1/(H-1), x1/(W-1), y2/(H-1), x2/(W-1)], 1), rois[:, 0].int())
yb = F.avg_pool2d(yb, sampling_ratio)

print('ya:\n', ya)
print('yb:\n', yb)
print('IsEqual: ', yb.equal(ya)) 

one case of output:

ya:
 tensor([[[[-0.9476,  0.1967,  0.0017],
          [-0.9198,  0.2392, -0.0529],
          [-0.3397,  0.1514, -0.0426]]]])
yb:
 tensor([[[[-1.0746,  0.1233, -0.0497],
          [-1.3218,  0.2025, -0.1869],
          [-0.5540,  0.1371, -0.1202]]]])
IsEqual:  False

I am not sure whether I have some misunderstanding of RoIAlign or there is some problem in using CropAndResize. I could not appreciate it more if anyone offers help.

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