MCPcopy Create free account
hub / github.com/ZhengPeng7/BiRefNet / ResBlk

Class ResBlk

models/modules/decoder_blocks.py:36–66  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34
35
36class ResBlk(nn.Module):
37 def __init__(self, in_channels=64, out_channels=None, inter_channels=64):
38 super(ResBlk, self).__init__()
39 if out_channels is None:
40 out_channels = in_channels
41 inter_channels = in_channels // 4 if config.dec_channels_inter == 'adap' else 64
42
43 self.conv_in = nn.Conv2d(in_channels, inter_channels, 3, 1, padding=1)
44 self.bn_in = nn.BatchNorm2d(inter_channels) if config.batch_size > 1 else nn.Identity()
45 self.relu_in = nn.ReLU(inplace=True)
46
47 if config.dec_att == 'ASPP':
48 self.dec_att = ASPP(in_channels=inter_channels)
49 elif config.dec_att == 'ASPPDeformable':
50 self.dec_att = ASPPDeformable(in_channels=inter_channels)
51
52 self.conv_out = nn.Conv2d(inter_channels, out_channels, 3, 1, padding=1)
53 self.bn_out = nn.BatchNorm2d(out_channels) if config.batch_size > 1 else nn.Identity()
54
55 self.conv_resi = nn.Conv2d(in_channels, out_channels, 1, 1, 0)
56
57 def forward(self, x):
58 _x = self.conv_resi(x)
59 x = self.conv_in(x)
60 x = self.bn_in(x)
61 x = self.relu_in(x)
62 if hasattr(self, 'dec_att'):
63 x = self.dec_att(x)
64 x = self.conv_out(x)
65 x = self.bn_out(x)
66 return x + _x
67
68
69class HierarAttDecBlk(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected