fpn
model.neck.fpn
ConvBlock
ConvBlock(in_channels: int, out_channels: int, kernel_size: int = 1, stride: int = 1, padding: int = 0)
Bases: Module
ConvBlock defined, which consists of Convolution, BatchNorm, ReLU
Attributes:
-
conv(Conv2d) –convolution layer for ConvBlock
-
bn(BatchNorm2d) –2d batch norm layer for ConvBlock
-
act(ReLU) –ReLU activation function for ConvBlock
initializing ConvBlock
Parameters:
-
in_channels(int) –'input channel' for conv layer
-
out_channels(int) –'output channel' for conv layer, which is also 'input channel' for bn layer
-
kernel_size(int, default:1) –kernel size for conv layer. Defaults to 1.
-
stride(int, default:1) –stride for conv layer. Defaults to 1.
-
padding(int, default:0) –padding for conv layer. Defaults to 0.
Source code in SaigeToolkit/model/neck/fpn.py
forward
forward function for nn.Module class
Parameters:
-
inputs(Tensor) –input tensor for ConvBlock
Returns:
-
Tensor–torch.Tensor: output tensor for ConvBlock
Source code in SaigeToolkit/model/neck/fpn.py
FpnBlock
FpnBlock(in_channels: Union[List[int], int, None] = [64, 128, 256, 512], out_channels: Union[List[int], int, None] = None, channel_fpn: int = 64, num_feat: int = 4)
Bases: Module
block for constructing FeaturePyramidNetwork.
Attributes:
-
block_in(ModuleList) –Convolution layer, that backbone output feature is directly applied
-
block_out(ModuleList) –Convolution layer, that tensors from 'block_in' is applied after 'upsampled and sumed'
initializing FpnBlock
Parameters:
-
in_channels(Union[List[int], int, None], default:[64, 128, 256, 512]) –input channels for block_in. Defaults to [64, 128, 256, 512].
-
out_channels(Union[List[int], int, None], default:None) –output channels for block_out. Defaults to None.
-
channel_fpn(int, default:64) –output channels for block_in, also input channels for block_out. Defaults to 64.
-
num_feat(int, default:4) –number of layer of block_in/block_out. Defaults to 4.
Source code in SaigeToolkit/model/neck/fpn.py
_upsample_add
upsample intput x to size of input y, and sum both inputs
Parameters:
-
x(Tensor) –smaller (size) input
-
y(Tensor) –larger (size) input
Returns:
-
Tensor–torch.Tensor: upsampled and sumed tensor
Source code in SaigeToolkit/model/neck/fpn.py
forward
forward function for nn.Module class
Parameters:
-
features(List[Tensor]) –list of tensors from backbone network
Returns:
-
List[Tensor]–List[torch.Tensor]: list of tensors processed after FpnBlock
Source code in SaigeToolkit/model/neck/fpn.py
FPN
FPN(in_channels: Optional[List[int]] = None, out_channels: int = 64, channel_fpn: int = 256, num_feat: int = 4, num_block: int = 1)
Bases: Module
"Feature Pyramid Networks for Object Detection".
Attributes:
-
block_fpn(ModuleList) –torch module list, consists of FpnBlocks.
initializing Feature Pyramid Networks
Parameters:
-
in_channels(List[int], default:None) –channels from backbone network output tensors. Defaults to None.
-
out_channels(int, default:64) –final output channels for FPN. Defaults to 64.
-
channel_fpn(int, default:256) –inner channels for FpnBlocks. Defaults to 256.
-
num_feat(int, default:4) –number of blocks inside of FpnBlocks. Defaults to 4.
-
num_block(int, default:1) –number of FpnBlocks. Defaults to 1.
Source code in SaigeToolkit/model/neck/fpn.py
forward
forward function for FPN
Parameters:
-
features(List[Tensor]) –output tensors from backbone network.
Returns:
-
List[Tensor]–List[torch.Tensor]: output tensors from FPN.
Source code in SaigeToolkit/model/neck/fpn.py
BiFpnBlock
Bases: Module
block for constructing BidirectionalFeaturePyramidNetwork.
Attributes:
-
epsilon(float) –epsilon value for BiFpnBlock
-
block_td(ModuleList) –blocks for
upsample_weighted_sum -
block_out(ModuleList) –blocks for
downsample_weighted_sum -
w1(Parameter) –weight parameter for block_td
-
w1_relu(ReLU) –ReLU layer for
w1parameter -
w2(Parameter) –weight parameter for block_out
-
w2_relu(ReLU) –ReLU layer for
w2parameter
initializing BiFpnBlock
Parameters:
-
channel_fpn(int, default:256) –input/output channels for all blocks. Defaults to 256.
-
num_feat(int, default:4) –number of each blocks. Defaults to 4.
-
epsilon(float, default:1e-06) –epsilon value for attribute
self.epsilon. Defaults to 1e-6.
Source code in SaigeToolkit/model/neck/fpn.py
forward
forward function for nn.Module
Parameters:
-
inputs(List[Tensor]) –list of tensors from former network
Returns:
-
List[Tensor]–List[torch.Tensor]: output list of tensors from BiFpnBlock
Source code in SaigeToolkit/model/neck/fpn.py
_upsample_weighted_sum
upsample input x and weighted sum with input y
Parameters:
-
x(Tensor) –smaller (size) input
-
y(Tensor) –larger (size) input
-
w(Parameter) –weight parameter
Returns:
-
Tensor–torch.Tensor: 'upsample_weight_sum'ed output
Source code in SaigeToolkit/model/neck/fpn.py
_downsample_weighted_sum
downsample input z and weighted sum with input x and input y
Parameters:
-
x(Tensor) –smaller (size) input
-
y(Tensor) –smaller (size) input
-
z(Tensor) –larger (size) input
-
w(Parameter) –weight parameter
Returns:
-
Tensor–torch.Tensor: 'downsample_weight_sum'ed output
Source code in SaigeToolkit/model/neck/fpn.py
BiFPN
BiFPN(in_channels: Optional[List[int]] = None, out_channels: int = 64, channel_fpn: int = 256, num_feat: int = 4, num_block: int = 2)
Bases: Module
"BidirectionalFeaturePyramidNetwork".
Attribute
block_in (nn.ModuleList): list of conv layers, which transfers input channels into fixed channel_fpn block_ex (nn.ModuleList): list of ConvBlock, residual blocks block_fpn (nn.ModuleList): list of BiFpnBlocks block_rtn (nn.ModuleList): list of ConvBlock, refining BiFpnBlock output
initializing Bidirectional FPN
Args:
in_channels (List[int], optional): channels from backbone network output tensors. Defaults to None.
out_channels (int, optional): final output channels for FPN. Defaults to 64.
channel_fpn (int, optional): inner channels for BiFpnBlocks. Defaults to 256.
num_feat (int, optional): number of blocks inside of BiFpnBlocks. Defaults to 4.
num_block (int, optional): number of FpnBlocks. Defaults to 1.
Source code in SaigeToolkit/model/neck/fpn.py
forward
forward function for FPN
Parameters:
-
inputs(List[Tensor]) –output tensors from backbone network.
Returns:
-
List[Tensor]–List[torch.Tensor]: output tensors from BiFPN.
Source code in SaigeToolkit/model/neck/fpn.py
FPN_DB
FPN_DB(in_channels: Optional[List[int]] = None, inner_channels: int = 256, bias: bool = False, *args, **kwargs)
Bases: Module
bias: Whether conv layers have bias or not.