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

Class ResBlock

code/dc_ldm/modules/diffusionmodules/openaimodel.py:165–277  ·  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

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

Callers 2

__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected