MCPcopy Create free account
hub / github.com/OpenImagingLab/FlashVSR / Downsample2D

Class Downsample2D

diffsynth/models/stepvideo_vae.py:198–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

196
197
198class Downsample2D(nn.Module):
199 def __init__(self, channels, use_conv=False, out_channels=None, padding=1):
200 super().__init__()
201 self.channels = channels
202 self.out_channels = out_channels or channels
203 self.use_conv = use_conv
204 self.padding = padding
205 stride = 2
206
207 if use_conv:
208 self.conv = nn.Conv2d(self.channels, self.out_channels, 3, stride=stride, padding=padding)
209 else:
210 assert self.channels == self.out_channels
211 self.conv = nn.AvgPool2d(kernel_size=stride, stride=stride)
212
213 def forward(self, x):
214 assert x.shape[-1] == self.channels
215 if self.use_conv and self.padding == 0:
216 pad = (0, 0, 0, 1, 0, 1)
217 x = F.pad(x, pad, mode="constant", value=0)
218
219 assert x.shape[-1] == self.channels
220 # x = self.conv(x)
221 x = base_conv2d(x, self.conv, channel_last=True)
222 return x
223
224
225

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected