MCPcopy Create free account
hub / github.com/dome272/Diffusion-Models-pytorch / Up

Class Up

modules.py:102–125  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

100
101
102class Up(nn.Module):
103 def __init__(self, in_channels, out_channels, emb_dim=256):
104 super().__init__()
105
106 self.up = nn.Upsample(scale_factor=2, mode="bilinear", align_corners=True)
107 self.conv = nn.Sequential(
108 DoubleConv(in_channels, in_channels, residual=True),
109 DoubleConv(in_channels, out_channels, in_channels // 2),
110 )
111
112 self.emb_layer = nn.Sequential(
113 nn.SiLU(),
114 nn.Linear(
115 emb_dim,
116 out_channels
117 ),
118 )
119
120 def forward(self, x, skip_x, t):
121 x = self.up(x)
122 x = torch.cat([skip_x, x], dim=1)
123 x = self.conv(x)
124 emb = self.emb_layer(t)[:, :, None, None].repeat(1, 1, x.shape[-2], x.shape[-1])
125 return x + emb
126
127
128class UNet(nn.Module):

Callers 2

__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected