MCPcopy Create free account
hub / github.com/IceClear/StableSR / Downsample

Class Downsample

ldm/modules/diffusionmodules/model.py:98–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

96
97
98class Downsample(nn.Module):
99 def __init__(self, in_channels, with_conv):
100 super().__init__()
101 self.with_conv = with_conv
102 if self.with_conv:
103 # no asymmetric padding in torch conv, must do it ourselves
104 self.conv = torch.nn.Conv2d(in_channels,
105 in_channels,
106 kernel_size=3,
107 stride=2,
108 padding=0)
109
110 def forward(self, x):
111 if self.with_conv:
112 pad = (0,1,0,1)
113 x = torch.nn.functional.pad(x, pad, mode="constant", value=0)
114 x = self.conv(x)
115 else:
116 x = torch.nn.functional.avg_pool2d(x, kernel_size=2, stride=2)
117 return x
118
119
120class ResnetBlock(nn.Module):

Callers 3

__init__Method · 0.70
__init__Method · 0.70
__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected