I am a pytorch beginner. Recently I am trying to implement the ROIAlign in PyTorch withCropAndResize 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))
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.
Hi,
I am a pytorch beginner. Recently I am trying to implement the ROIAlign in PyTorch with
CropAndResize
andtorch.nn.functional.max_pool2d
. But the output is different fromtorchvision.ops.RoIAlign
.code:
one case of output:
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.