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])