快捷方式

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 的检测都很有用。

它通过特征金字塔网络论文的公式 1 中指定的启发式方法推断池化的尺度。仅关键字参数 canonical_scalecanonical_level 分别对应于公式 1 中的 224k0=4,并具有以下含义:canonical_level 是金字塔的目标层级,从中池化一个感兴趣区域,其 w x h = canonical_scale x canonical_scale

参数:
  • featmap_names (List[str]) – 将用于池化的特征图的名称。

  • output_size (List[Tuple[int, int]] or List[int]) – 池化区域的输出大小

  • sampling_ratio (int) – ROIAlign 的采样率

  • canonical_scale (int, 可选) – LevelMapper 的 canonical_scale

  • canonical_level (int, 可选) – LevelMapper 的 canonical_level

示例

>>> 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, Tensor], boxes: List[Tensor], image_shapes: List[Tuple[int, int]]) Tensor[源代码]
参数:
  • x (OrderedDict[Tensor]) – 每个层级的特征图。 它们被假定为具有相同的通道数,但可以具有不同的大小。

  • boxes (List[Tensor[N, 4]]) – 用于执行池化操作的框,格式为 (x1, y1, x2, y2),并且在图像参考大小中,而不是特征图参考中。 坐标必须满足 0 <= x1 < x20 <= y1 < y2

  • image_shapes (List[Tuple[height, width]]) – 每张图像在被馈送到 CNN 以获得特征图之前的大小。 这允许我们推断要池化的每个层级的比例因子。

返回:

result (Tensor)

文档

访问 PyTorch 的全面开发者文档

查看文档

教程

获取面向初学者和高级开发者的深入教程

查看教程

资源

查找开发资源并获得您的问题解答

查看资源