快捷方式

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)[源代码]

Multi-scale 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 开发者文档

查看文档

教程

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

查看教程

资源

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

查看资源