For a set of image sizes and feature maps, computes a set
of anchors对于一组图像大小和feature maps,计算一组锚点
传入的是
anchor_sizes = config.MODEL.RPN.ANCHOR_SIZES #(32, 64, 128, 256, 512)
aspect_ratios = config.MODEL.RPN.ASPECT_RATIOS #(0.5, 1.0, 2.0)
anchor_stride = config.MODEL.RPN.ANCHOR_STRIDE #(4, 8, 16, 32, 64) 也就是P2~P6
straddle_thresh = config.MODEL.RPN.STRADDLE_THRESH # 0
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
import math
import numpy as np
import torch
from torch import nn
from maskrcnn_benchmark.structures.bounding_box import BoxList
class BufferList(nn.Module):
"""
Similar to nn.ParameterList, but for buffers
"""
def __init__(self, buffers=None):
super(BufferList, self).__init__()
if buffers is not None:
self.extend(buffers)
def extend(self, buffers):
offset = len(self)
for i, buffer in enumerate(buffers):
self.register_buffer(str(offset + i), buffer)
return self
def __len__(self):
return len(self._buffers)
def __iter__(self):
return iter(self._buffers.values())
class AnchorGenerator(nn.Module):
"""
For a set of image sizes and feature maps, computes a set
of anchors对于一组图像大小和feature maps,计算一组锚点
传入的是
anchor_sizes = config.MODEL.RPN.ANCHOR_SIZES #(32, 64, 128, 256, 512)
aspect_ratios = config.MODEL.RPN.ASPECT_RATIOS #(0.5, 1.0, 2.0)
anchor_stride = config.MODEL.RPN.ANCHOR_STRIDE #(4, 8, 16, 32, 64) 也就是P2~P6
straddle_thresh = config.MODEL.RPN.STRADDLE_THRESH # 0
"""
def __init__(
self,
sizes=(128, 256, 512),
aspect_ratios=(0.5, 1.0, 2.0),
anchor_strides=(8, 16, 32),
straddle_thresh=0,
):
super(AnchorGenerator, self).__init__()
if len(anchor_strides) == 1:
anchor_stride = anchor_strides[0]
cell_anchors = [
generate_anchors(anchor_stride, sizes, aspect_ratios).float()
]
else:
if len(anchor_strides) != len(sizes):
raise RuntimeError("FPN should have #anchor_strides == #sizes")
# TODO 会运行到这里 以(x1&#x