MCPcopy Create free account
hub / github.com/alinlab/SelfPatch / AttentionRefinementModule

Class AttentionRefinementModule

segmentation/backbones/bisenetv1.py:84–126  ·  view source on GitHub ↗

Attention Refinement Module (ARM) to refine the features of each stage. Args: in_channels (int): The number of input channels. out_channels (int): The number of output channels. Returns: x_out (torch.Tensor): Feature map of Attention Refinement Module.

Source from the content-addressed store, hash-verified

82
83
84class AttentionRefinementModule(BaseModule):
85 """Attention Refinement Module (ARM) to refine the features of each stage.
86
87 Args:
88 in_channels (int): The number of input channels.
89 out_channels (int): The number of output channels.
90 Returns:
91 x_out (torch.Tensor): Feature map of Attention Refinement Module.
92 """
93
94 def __init__(self,
95 in_channels,
96 out_channel,
97 conv_cfg=None,
98 norm_cfg=dict(type='BN'),
99 act_cfg=dict(type='ReLU'),
100 init_cfg=None):
101 super(AttentionRefinementModule, self).__init__(init_cfg=init_cfg)
102 self.conv_layer = ConvModule(
103 in_channels=in_channels,
104 out_channels=out_channel,
105 kernel_size=3,
106 stride=1,
107 padding=1,
108 conv_cfg=conv_cfg,
109 norm_cfg=norm_cfg,
110 act_cfg=act_cfg)
111 self.atten_conv_layer = nn.Sequential(
112 nn.AdaptiveAvgPool2d((1, 1)),
113 ConvModule(
114 in_channels=out_channel,
115 out_channels=out_channel,
116 kernel_size=1,
117 bias=False,
118 conv_cfg=conv_cfg,
119 norm_cfg=norm_cfg,
120 act_cfg=None), nn.Sigmoid())
121
122 def forward(self, x):
123 x = self.conv_layer(x)
124 x_atten = self.atten_conv_layer(x)
125 x_out = x * x_atten
126 return x_out
127
128
129class ContextPath(BaseModule):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected