快捷方式

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_scalecanonical_level 分別對應公式 1 中的 224k0=4,其含義如下:canonical_level 是金字塔中用於對寬度 x 高度 = canonical_scale x canonical_scale 的感興趣區域進行池化的目標層級。

引數
  • featmap_names (List[str]) – 將用於池化的特徵圖名稱。

  • output_size (Union[int, Tuple[int, int], 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[source]
引數
  • 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 的全面開發者文件

檢視文件

教程

獲取面向初學者和高階開發者的深度教程

檢視教程

資源

查詢開發資源並獲得問題解答

檢視資源