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

Class ResBlock

diff2flow/models/unet/openaimodel.py:166–278  ·  view source on GitHub ↗

A residual block that can optionally change the number of channels. :param channels: the number of input channels. :param emb_channels: the number of timestep embedding channels. :param dropout: the rate of dropout. :param out_channels: if specified, the number of out channels.

Source from the content-addressed store, hash-verified

164
165
166class ResBlock(TimestepBlock):
167 """
168 A residual block that can optionally change the number of channels.
169 :param channels: the number of input channels.
170 :param emb_channels: the number of timestep embedding channels.
171 :param dropout: the rate of dropout.
172 :param out_channels: if specified, the number of out channels.
173 :param use_conv: if True and out_channels is specified, use a spatial
174 convolution instead of a smaller 1x1 convolution to change the
175 channels in the skip connection.
176 :param dims: determines if the signal is 1D, 2D, or 3D.
177 :param use_checkpoint: if True, use gradient checkpointing on this module.
178 :param up: if True, use this block for upsampling.
179 :param down: if True, use this block for downsampling.
180 """
181
182 def __init__(
183 self,
184 channels,
185 emb_channels,
186 dropout,
187 out_channels=None,
188 use_conv=False,
189 use_scale_shift_norm=False,
190 dims=2,
191 use_checkpoint=False,
192 up=False,
193 down=False,
194 ):
195 super().__init__()
196 self.channels = channels
197 self.emb_channels = emb_channels
198 self.dropout = dropout
199 self.out_channels = out_channels or channels
200 self.use_conv = use_conv
201 self.use_checkpoint = use_checkpoint
202 self.use_scale_shift_norm = use_scale_shift_norm
203
204 self.in_layers = nn.Sequential(
205 normalization(channels),
206 nn.SiLU(),
207 conv_nd(dims, channels, self.out_channels, 3, padding=1),
208 )
209
210 self.updown = up or down
211
212 if up:
213 self.h_upd = Upsample(channels, False, dims)
214 self.x_upd = Upsample(channels, False, dims)
215 elif down:
216 self.h_upd = Downsample(channels, False, dims)
217 self.x_upd = Downsample(channels, False, dims)
218 else:
219 self.h_upd = self.x_upd = nn.Identity()
220
221 self.emb_layers = nn.Sequential(
222 nn.SiLU(),
223 linear(

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected