Context Embedding Block for large receptive filed in Semantic Branch. Args: in_channels (int): Number of input channels. Default: 3. out_channels (int): Number of output channels. Default: 16. conv_cfg (dict | None): Config of conv layers.
| 300 | |
| 301 | |
| 302 | class CEBlock(BaseModule): |
| 303 | """Context Embedding Block for large receptive filed in Semantic Branch. |
| 304 | |
| 305 | Args: |
| 306 | in_channels (int): Number of input channels. |
| 307 | Default: 3. |
| 308 | out_channels (int): Number of output channels. |
| 309 | Default: 16. |
| 310 | conv_cfg (dict | None): Config of conv layers. |
| 311 | Default: None. |
| 312 | norm_cfg (dict | None): Config of norm layers. |
| 313 | Default: dict(type='BN'). |
| 314 | act_cfg (dict): Config of activation layers. |
| 315 | Default: dict(type='ReLU'). |
| 316 | init_cfg (dict or list[dict], optional): Initialization config dict. |
| 317 | Default: None. |
| 318 | Returns: |
| 319 | x (torch.Tensor): Last feature map in Semantic Branch. |
| 320 | """ |
| 321 | |
| 322 | def __init__(self, |
| 323 | in_channels=3, |
| 324 | out_channels=16, |
| 325 | conv_cfg=None, |
| 326 | norm_cfg=dict(type='BN'), |
| 327 | act_cfg=dict(type='ReLU'), |
| 328 | init_cfg=None): |
| 329 | super(CEBlock, self).__init__(init_cfg=init_cfg) |
| 330 | self.in_channels = in_channels |
| 331 | self.out_channels = out_channels |
| 332 | self.gap = nn.Sequential( |
| 333 | nn.AdaptiveAvgPool2d((1, 1)), |
| 334 | build_norm_layer(norm_cfg, self.in_channels)[1]) |
| 335 | self.conv_gap = ConvModule( |
| 336 | in_channels=self.in_channels, |
| 337 | out_channels=self.out_channels, |
| 338 | kernel_size=1, |
| 339 | stride=1, |
| 340 | padding=0, |
| 341 | conv_cfg=conv_cfg, |
| 342 | norm_cfg=norm_cfg, |
| 343 | act_cfg=act_cfg) |
| 344 | # Note: in paper here is naive conv2d, no bn-relu |
| 345 | self.conv_last = ConvModule( |
| 346 | in_channels=self.out_channels, |
| 347 | out_channels=self.out_channels, |
| 348 | kernel_size=3, |
| 349 | stride=1, |
| 350 | padding=1, |
| 351 | conv_cfg=conv_cfg, |
| 352 | norm_cfg=norm_cfg, |
| 353 | act_cfg=act_cfg) |
| 354 | |
| 355 | def forward(self, x): |
| 356 | identity = x |
| 357 | x = self.gap(x) |
| 358 | x = self.conv_gap(x) |
| 359 | x = identity + x |