MCPcopy Create free account
hub / github.com/CompVis/diff2flow / Downsample

Class Downsample

diff2flow/kl_autoencoder.py:103–118  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected