MultiScaleRoIAlign¶
- class torchvision.ops.MultiScaleRoIAlign(featmap_names: list[str], output_size: Union[int, tuple[int], list[int]], sampling_ratio: int, *, canonical_scale: int = 224, canonical_level: int = 4)[源代码]¶
多尺度 RoIAlign 池化,对于带或不带 FPN 的检测很有用。
它通过 Feature Pyramid Network 论文 公式 1 中指定的启发式方法推断池化尺度。关键字参数
canonical_scale
和canonical_level
分别对应公式 1 中的224
和k0=4
,其含义如下:canonical_level
是金字塔的目標層級,將從該層級池化一個尺寸為w x h = canonical_scale x canonical_scale
的感興趣區域。- 参数:
示例
>>> m = torchvision.ops.MultiScaleRoIAlign(['feat1', 'feat3'], 3, 2) >>> i = OrderedDict() >>> i['feat1'] = torch.rand(1, 5, 64, 64) >>> i['feat2'] = torch.rand(1, 5, 32, 32) # this feature won't be used in the pooling >>> i['feat3'] = torch.rand(1, 5, 16, 16) >>> # create some random bounding boxes >>> boxes = torch.rand(6, 4) * 256; boxes[:, 2:] += boxes[:, :2] >>> # original image size, before computing the feature maps >>> image_sizes = [(512, 512)] >>> output = m(i, [boxes], image_sizes) >>> print(output.shape) >>> torch.Size([6, 5, 3, 3])
- forward(x: dict[str, torch.Tensor], boxes: list[torch.Tensor], image_shapes: list[tuple[int, int]]) Tensor [源代码]¶
- 参数:
x (OrderedDict[Tensor]) – 每个层级的特征图。假设它们具有相同的通道数,但尺寸可能不同。
boxes (List[Tensor[N, 4]]) – 用于执行池化操作的边界框,格式为 (x1, y1, x2, y2),以图像的参考尺寸表示,而不是特征图的参考尺寸。坐标必须满足
0 <= x1 < x2
和0 <= y1 < y2
。image_shapes (List[Tuple[height, width]]) – 输入 CNN 以获取特征图之前的每个图像的尺寸。这使我们能够推断每个层级的比例因子以进行池化。
- 返回:
result (Tensor)