Channel Mapper to reduce/increase channels of backbone features. This is used to reduce/increase channels of backbone features. Args: in_channels (List[int]): Number of input channels per scale. out_channels (int): Number of output channels (used at each scale). ker
| 17 | |
| 18 | @MODELS.register_module() |
| 19 | class ChannelMapper(BaseModule): |
| 20 | """Channel Mapper to reduce/increase channels of backbone features. |
| 21 | |
| 22 | This is used to reduce/increase channels of backbone features. |
| 23 | |
| 24 | Args: |
| 25 | in_channels (List[int]): Number of input channels per scale. |
| 26 | out_channels (int): Number of output channels (used at each scale). |
| 27 | kernel_size (int, optional): kernel_size for reducing channels (used |
| 28 | at each scale). Default: 3. |
| 29 | conv_cfg (:obj:`ConfigDict` or dict, optional): Config dict for |
| 30 | convolution layer. Default: None. |
| 31 | norm_cfg (:obj:`ConfigDict` or dict, optional): Config dict for |
| 32 | normalization layer. Default: None. |
| 33 | act_cfg (:obj:`ConfigDict` or dict, optional): Config dict for |
| 34 | activation layer in ConvModule. Default: dict(type='ReLU'). |
| 35 | bias (bool | str): If specified as `auto`, it will be decided by the |
| 36 | norm_cfg. Bias will be set as True if `norm_cfg` is None, otherwise |
| 37 | False. Default: "auto". |
| 38 | init_cfg (:obj:`ConfigDict` or dict or list[:obj:`ConfigDict` or dict], |
| 39 | optional): Initialization config dict. |
| 40 | Example: |
| 41 | >>> import torch |
| 42 | >>> in_channels = [2, 3, 5, 7] |
| 43 | >>> scales = [340, 170, 84, 43] |
| 44 | >>> inputs = [torch.rand(1, c, s, s) |
| 45 | ... for c, s in zip(in_channels, scales)] |
| 46 | >>> self = ChannelMapper(in_channels, 11, 3).eval() |
| 47 | >>> outputs = self.forward(inputs) |
| 48 | >>> for i in range(len(outputs)): |
| 49 | ... print(f'outputs[{i}].shape = {outputs[i].shape}') |
| 50 | outputs[0].shape = torch.Size([1, 11, 340, 340]) |
| 51 | outputs[1].shape = torch.Size([1, 11, 170, 170]) |
| 52 | outputs[2].shape = torch.Size([1, 11, 84, 84]) |
| 53 | outputs[3].shape = torch.Size([1, 11, 43, 43]) |
| 54 | """ |
| 55 | |
| 56 | def __init__(self, |
| 57 | in_channels: List[int], |
| 58 | out_channels: int, |
| 59 | kernel_size: int = 1, |
| 60 | init_cfg: Optional[dict] = None) -> None: |
| 61 | super().__init__(init_cfg=init_cfg) |
| 62 | assert isinstance(in_channels, list) |
| 63 | self.convs = nn.ModuleList() |
| 64 | for in_channel in in_channels: |
| 65 | self.convs.append( |
| 66 | self._make_conv_block(in_channel, out_channels, kernel_size)) |
| 67 | |
| 68 | def _make_conv_block(self, in_channels: int, out_channels: int, |
| 69 | kernel_size: int) -> nn.Module: |
| 70 | """Construct DeConv-Norm-Act-Conv-Norm-Act block. |
| 71 | |
| 72 | Args: |
| 73 | in_channels (int): Number of input channels. |
| 74 | out_channels (int): Number of output channels. |
| 75 | |
| 76 | Returns: |
nothing calls this directly
no outgoing calls
no test coverage detected