我是 pytorch 初学者。看来pytorch中的RoIAlign模块有bug。代码很简单,但结果出乎我的意料。
代码:
import torch
from torchvision.ops import RoIAlign
if __name__ == '__main__':
output_size = (3,3)
spatial_scale = 1/4
sampling_ratio = 2
#x.shape:(1,1,6,6)
x = torch.FloatTensor([[
[[1,2,3,4,5,6],
[7,8,9,10,11,12],
[13,14,15,16,17,18],
[19,20,21,22,23,24],
[25,26,27,28,29,30],
[31,32,33,34,35,36],],
]])
rois = torch.tensor([
[0,0.0,0.0,20.0,20.0],
])
channel_num = x.shape[1]
roi_num = rois.shape[0]
a = RoIAlign(output_size, spatial_scale=spatial_scale, sampling_ratio=sampling_ratio)
ya = a(x, rois)
print(ya)
输出:
tensor([[[[ 6.8333, 8.5000, 10.1667],
[16.8333, 18.5000, 20.1667],
[26.8333, 28.5000, 30.1667]]]])
但在这种情况下,它不应该是每个 2x2 单元格上的平均池化操作,例如:
tensor([[[[ 4.5000, 6.5000, 8.5000],
[16.5000, 18.5000, 20.5000],
[28.5000, 30.5000, 32.5000]]]])
我的 Torch 版本是 1.3.0,带有 python3.6 和 cuda 10.1,在 Ubuntu16 上。我已经困扰了两天,如果有人可以帮助我,我将不胜感激。