(
        self,
        bottom_up: M.Module,
        in_features: List[str],
        out_channels: int = 256,
        norm: str = None,
        top_block: M.Module = None,
        strides: List[int] = [8, 16, 32],
        channels: List[int] = [512, 1024, 2048],
    )
Args:
            bottom_up (M.Module): module representing the bottom up sub-network.
                it generates multi-scale feature maps which formatted as a
                dict like {'res3': res3_feature, 'res4': res4_feature}
            in_features (list[str]): list of input feature maps keys coming
                from the `bottom_up` which will be used in FPN.
                e.g. ['res3', 'res4', 'res5']
            out_channels (int): number of channels used in the output
                feature maps.
            norm (str): the normalization type.
            top_block (nn.Module or None): the module build upon FPN layers.
Args:
            bottom_up (M.Module): module representing the bottom up sub-network.
                it generates multi-scale feature maps which formatted as a
                dict like {'res3': res3_feature, 'res4': res4_feature}
            in_features (list[str]): list of input feature maps keys coming
                from the `bottom_up` which will be used in FPN.
                e.g. ['res3', 'res4', 'res5']
            out_channels (int): number of channels used in the output
                feature maps.
            norm (str): the normalization type.
            top_block (nn.Module or None): the module build upon FPN layers.
Args : bottom_up ( M . Module ) : module representing the bottom up sub - network . it generates multi - scale feature maps which formatted as a dict like { res3 : res3_feature res4 : res4_feature } in_features ( list [ str ] ) : list of input feature maps keys coming from the bottom_up which will be used in FPN . e . g . [ res3 res4 res5 ] out_channels ( int ) : number of channels used in the output feature maps . norm ( str ) : the normalization type . top_block ( nn . Module or None ) : the module build upon FPN layers .
def __init__(
        self,
        bottom_up: M.Module,
        in_features: List[str],
        out_channels: int = 256,
        norm: str = None,
        top_block: M.Module = None,
        strides: List[int] = [8, 16, 32],
        channels: List[int] = [512, 1024, 2048],
    ):
        """
        Args:
            bottom_up (M.Module): module representing the bottom up sub-network.
                it generates multi-scale feature maps which formatted as a
                dict like {'res3': res3_feature, 'res4': res4_feature}
            in_features (list[str]): list of input feature maps keys coming
                from the `bottom_up` which will be used in FPN.
                e.g. ['res3', 'res4', 'res5']
            out_channels (int): number of channels used in the output
                feature maps.
            norm (str): the normalization type.
            top_block (nn.Module or None): the module build upon FPN layers.
        """
        super(FPN, self).__init__()

        in_strides = strides
        in_channels = channels
        norm = layers.get_norm(norm)

        use_bias = norm is None
        self.lateral_convs = list()
        self.output_convs = list()

        for idx, in_channels in enumerate(in_channels):
            lateral_norm = None if norm is None else norm(out_channels)
            output_norm = None if norm is None else norm(out_channels)

            lateral_conv = layers.Conv2d(
                in_channels,
                out_channels,
                kernel_size=1,
                bias=use_bias,
                norm=lateral_norm,
            )
            output_conv = layers.Conv2d(
                out_channels,
                out_channels,
                kernel_size=3,
                stride=1,
                padding=1,
                bias=use_bias,
                norm=output_norm,
            )
            M.init.msra_normal_(lateral_conv.weight, mode="fan_in")
            M.init.msra_normal_(output_conv.weight, mode="fan_in")

            if use_bias:
                M.init.fill_(lateral_conv.bias, 0)
                M.init.fill_(output_conv.bias, 0)

            stage = int(math.log2(in_strides[idx]))

            setattr(self, "fpn_lateral{}".format(stage), lateral_conv)
            setattr(self, "fpn_output{}".format(stage), output_conv)
            self.lateral_convs.insert(0, lateral_conv)
            self.output_convs.insert(0, output_conv)

        self.top_block = top_block
        self.in_features = in_features
        self.bottom_up = bottom_up

        # follow the common practices, FPN features are named to "p<stage>",
        # like ["p2", "p3", ..., "p6"]
        self._out_feature_strides = {
            "p{}".format(int(math.log2(s))): s for s in in_strides
        }

        # top block output feature maps.
        if self.top_block is not None:
            for s in range(stage, stage + self.top_block.num_levels):
                self._out_feature_strides["p{}".format(s + 1)] = 2 ** (s + 1)

        self._out_features = list(sorted(self._out_feature_strides.keys()))
        self._out_feature_channels = {k: out_channels for k in self._out_features}
def __init__ ( self , bottom_up : M . Module , in_features : List [ str ] , out_channels : int = 256 , norm : str = None , top_block : M . Module = None , strides : List [ int ] = [ 8 , 16 , 32 ] , channels : List [ int ] = [ 512 , 1024 , 2048 ] , ) : super ( FPN , self ) . __init__ ( ) in_strides = strides in_channels = channels norm = layers . get_norm ( norm ) use_bias = norm is None self . lateral_convs = list ( ) self . output_convs = list ( ) for idx , in_channels in enumerate ( in_channels ) : lateral_norm = None if norm is None else norm ( out_channels ) output_norm = None if norm is None else norm ( out_channels ) lateral_conv = layers . Conv2d ( in_channels , out_channels , kernel_size = 1 , bias = use_bias , norm = lateral_norm , ) output_conv = layers . Conv2d ( out_channels , out_channels , kernel_size = 3 , stride = 1 , padding = 1 , bias = use_bias , norm = output_norm , ) M . init . msra_normal_ ( lateral_conv . weight , mode = "fan_in" ) M . init . msra_normal_ ( output_conv . weight , mode = "fan_in" ) if use_bias : M . init . fill_ ( lateral_conv . bias , 0 ) M . init . fill_ ( output_conv . bias , 0 ) stage = int ( math . log2 ( in_strides [ idx ] ) ) setattr ( self , "fpn_lateral{}" . format ( stage ) , lateral_conv ) setattr ( self , "fpn_output{}" . format ( stage ) , output_conv ) self . lateral_convs . insert ( 0 , lateral_conv ) self . output_convs . insert ( 0 , output_conv ) self . top_block = top_block self . in_features = in_features self . bottom_up = bottom_up # follow the common practices, FPN features are named to "p<stage>", # like ["p2", "p3", ..., "p6"] self . _out_feature_strides = { "p{}" . format ( int ( math . log2 ( s ) ) ) : s for s in in_strides } # top block output feature maps. if self . top_block is not None : for s in range ( stage , stage + self . top_block . num_levels ) : self . _out_feature_strides [ "p{}" . format ( s + 1 ) ] = 2 ** ( s + 1 ) self . _out_features = list ( sorted ( self . _out_feature_strides . keys ( ) ) ) self . _out_feature_channels = { k : out_channels for k in self . _out_features }