快捷方式

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_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, 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 < x20 <= y1 < y2

  • image_shapes (List[Tuple[height, width]]) – 输入 CNN 以获取特征图之前的每个图像的尺寸。这使我们能够推断每个层级的比例因子以进行池化。

返回:

result (Tensor)

文档

访问全面的 PyTorch 开发者文档

查看文档

教程

为初学者和高级开发者提供深入的教程

查看教程

资源

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

查看资源