MCPcopy Create free account
hub / github.com/bbaaii/DreamDiffusion / Downsample

Class Downsample

code/dc_ldm/modules/diffusionmodules/openaimodel.py:136–162  ·  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 in

Source from the content-addressed store, hash-verified

134
135
136class Downsample(nn.Module):
137 """
138 A downsampling layer with an optional convolution.
139 :param channels: channels in the inputs and outputs.
140 :param use_conv: a bool determining if a convolution is applied.
141 :param dims: determines if the signal is 1D, 2D, or 3D. If 3D, then
142 downsampling occurs in the inner-two dimensions.
143 """
144
145 def __init__(self, channels, use_conv, dims=2, out_channels=None,padding=1):
146 super().__init__()
147 self.channels = channels
148 self.out_channels = out_channels or channels
149 self.use_conv = use_conv
150 self.dims = dims
151 stride = 2 if dims != 3 else (1, 2, 2)
152 if use_conv:
153 self.op = conv_nd(
154 dims, self.channels, self.out_channels, 3, stride=stride, padding=padding
155 )
156 else:
157 assert self.channels == self.out_channels
158 self.op = avg_pool_nd(dims, kernel_size=stride, stride=stride)
159
160 def forward(self, x):
161 assert x.shape[1] == self.channels
162 return self.op(x)
163
164
165class ResBlock(TimestepBlock):

Callers 3

__init__Method · 0.70
__init__Method · 0.70
__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected