MCPcopy Create free account
hub / github.com/DPS2022/diffusion-posterior-sampling / Downsample

Class Downsample

guided_diffusion/unet.py:184–211  ·  view source on GitHub ↗

A downsampling layer with an optional convolution. :param channels: channels in the inputs and outputs. :param use_conv: a bool determining if a convolution is applied. :param dims: determines if the signal is 1D, 2D, or 3D. If 3D, then downsampling occurs in the i

Source from the content-addressed store, hash-verified

182
183
184class Downsample(nn.Module):
185 """
186 A downsampling layer with an optional convolution.
187
188 :param channels: channels in the inputs and outputs.
189 :param use_conv: a bool determining if a convolution is applied.
190 :param dims: determines if the signal is 1D, 2D, or 3D. If 3D, then
191 downsampling occurs in the inner-two dimensions.
192 """
193
194 def __init__(self, channels, use_conv, dims=2, out_channels=None):
195 super().__init__()
196 self.channels = channels
197 self.out_channels = out_channels or channels
198 self.use_conv = use_conv
199 self.dims = dims
200 stride = 2 if dims != 3 else (1, 2, 2)
201 if use_conv:
202 self.op = conv_nd(
203 dims, self.channels, self.out_channels, 3, stride=stride, padding=1
204 )
205 else:
206 assert self.channels == self.out_channels
207 self.op = avg_pool_nd(dims, kernel_size=stride, stride=stride)
208
209 def forward(self, x):
210 assert x.shape[1] == self.channels
211 return self.op(x)
212
213
214class ResBlock(TimestepBlock):

Callers 3

__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected