MCPcopy Create free account
hub / github.com/Sin3DM/Sin3DM / __init__

Method __init__

src/encoding/blocks.py:190–235  ·  view source on GitHub ↗
(self, in_channels, out_channels, up=False, ks=3, input_norm=True, input_act=True)

Source from the content-addressed store, hash-verified

188
189class TriplaneGroupResnetBlock(nn.Module):
190 def __init__(self, in_channels, out_channels, up=False, ks=3, input_norm=True, input_act=True):
191 super().__init__()
192 in_channels *= 3
193 out_channels *= 3
194
195 self.in_channels = in_channels
196 self.out_channels = out_channels
197 self.up = up
198
199 self.input_norm = input_norm
200 if input_norm and input_act:
201 self.in_layers = nn.Sequential(
202 # nn.GroupNorm(num_groups=3, num_channels=in_channels, eps=1e-6, affine=True),
203 SiLU(),
204 nn.Conv2d(in_channels, out_channels, groups=3, kernel_size=ks, stride=1, padding=(ks - 1)//2)
205 )
206 elif not input_norm:
207 if input_act:
208 self.in_layers = nn.Sequential(
209 SiLU(),
210 nn.Conv2d(in_channels, out_channels, groups=3, kernel_size=ks, stride=1, padding=(ks - 1)//2)
211 )
212 else:
213 self.in_layers = nn.Sequential(
214 nn.Conv2d(in_channels, out_channels, groups=3, kernel_size=ks, stride=1, padding=(ks - 1)//2)
215 )
216 else:
217 raise NotImplementedError
218
219 self.norm_xy = nn.InstanceNorm2d(out_channels//3, eps=1e-6, affine=True)
220 self.norm_xz = nn.InstanceNorm2d(out_channels//3, eps=1e-6, affine=True)
221 self.norm_yz = nn.InstanceNorm2d(out_channels//3, eps=1e-6, affine=True)
222
223 self.out_layers = nn.Sequential(
224 # nn.GroupNorm(num_groups=3, num_channels=out_channels, eps=1e-6, affine=True),
225 SiLU(),
226 # nn.Dropout(p=dropout),
227 zero_module(
228 nn.Conv2d(out_channels, out_channels, groups=3, kernel_size=ks, stride=1, padding=(ks - 1)//2)
229 ),
230 )
231
232 if self.in_channels != self.out_channels:
233 self.shortcut = nn.Conv2d(in_channels, out_channels, groups=3, kernel_size=1, stride=1, padding=0)
234 else:
235 self.shortcut = nn.Identity()
236
237 def forward(self, feat_maps):
238 if self.input_norm:

Callers

nothing calls this directly

Calls 3

SiLUClass · 0.70
zero_moduleFunction · 0.70
__init__Method · 0.45

Tested by

no test coverage detected