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)[source]¶
多尺度 RoIAlign 池化,适用于带 FPN 或不带 FPN 的检测任务。
它通过 特征金字塔网络论文 中公式 1 中指定的启发式方法来推断池化尺度。关键字参数
canonical_scale
和canonical_level
分别对应公式 1 中的224
和k0=4
,其含义如下:canonical_level
是金字塔中用于对宽度 x 高度 =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])