pytorch torchvision.ops.roi_align

 最后发现pytorch的roialign不是和网上说的一样啊,他输入的bbox框坐标是需要相对于input的坐标的啊!比如inpu的featuremap的width是24,那么就要求框坐标是[0-23]之间的数!

下面要注意bbox的位置数值应该是大于1的数字,小数都是错的

import torchvision
import torch

input_ = torch.rand(3, 128, 24, 96) #[b,c,h,w]

bbox = [[0,0.1,0.15,0.4,0.6],
        [0,0.1,0.15,0.4,0.6],
[1,0.01,0.15,0.4,0.6],
[1,0.1,0.25,0.7,0.6],
[2,0.01,0.14,0.5,0.6],
[2,0.1,0.45,0.4,0.6],
[2,0.01,0.45,0.12,0.6],
[0,0.01,0.25,0.15,0.6]]

bbox_1 = torch.tensor(bbox)#[8,5]

#[8,128,7,7]
roi = torchvision.ops.roi_align(input=input_, boxes=bbox_1,
                                        output_size=(7, 7))

更多推荐