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

Class Downsample

diff2flow/models/unet/openaimodel.py:137–163  ·  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

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

Callers 2

__init__Method · 0.70
__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected