MCPcopy Create free account
hub / github.com/aigc3d/LHM / __init__

Method __init__

engine/BiRefNet/models/modules/aspp.py:34–87  ·  view source on GitHub ↗
(self, in_channels=64, out_channels=None, output_stride=16)

Source from the content-addressed store, hash-verified

32
33class ASPP(nn.Module):
34 def __init__(self, in_channels=64, out_channels=None, output_stride=16):
35 super(ASPP, self).__init__()
36 self.down_scale = 1
37 if out_channels is None:
38 out_channels = in_channels
39 self.in_channelster = 256 // self.down_scale
40 if output_stride == 16:
41 dilations = [1, 6, 12, 18]
42 elif output_stride == 8:
43 dilations = [1, 12, 24, 36]
44 else:
45 raise NotImplementedError
46
47 self.aspp1 = _ASPPModule(
48 in_channels, self.in_channelster, 1, padding=0, dilation=dilations[0]
49 )
50 self.aspp2 = _ASPPModule(
51 in_channels,
52 self.in_channelster,
53 3,
54 padding=dilations[1],
55 dilation=dilations[1],
56 )
57 self.aspp3 = _ASPPModule(
58 in_channels,
59 self.in_channelster,
60 3,
61 padding=dilations[2],
62 dilation=dilations[2],
63 )
64 self.aspp4 = _ASPPModule(
65 in_channels,
66 self.in_channelster,
67 3,
68 padding=dilations[3],
69 dilation=dilations[3],
70 )
71
72 self.global_avg_pool = nn.Sequential(
73 nn.AdaptiveAvgPool2d((1, 1)),
74 nn.Conv2d(in_channels, self.in_channelster, 1, stride=1, bias=False),
75 (
76 nn.BatchNorm2d(self.in_channelster)
77 if config.batch_size > 1
78 else nn.Identity()
79 ),
80 nn.ReLU(inplace=True),
81 )
82 self.conv1 = nn.Conv2d(self.in_channelster * 5, out_channels, 1, bias=False)
83 self.bn1 = (
84 nn.BatchNorm2d(out_channels) if config.batch_size > 1 else nn.Identity()
85 )
86 self.relu = nn.ReLU(inplace=True)
87 self.dropout = nn.Dropout(0.5)
88
89 def forward(self, x):
90 x1 = self.aspp1(x)

Callers 3

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 1

_ASPPModuleClass · 0.85

Tested by

no test coverage detected