MCPcopy Create free account
hub / github.com/YesianRohn/TextSSR / ResnetBlock2D

Class ResnetBlock2D

diffusers/src/diffusers/models/resnet.py:189–373  ·  view source on GitHub ↗

r""" A Resnet block. Parameters: in_channels (`int`): The number of channels in the input. out_channels (`int`, *optional*, default to be `None`): The number of output channels for the first conv2d layer. If None, same as `in_channels`. dropout (`float`,

Source from the content-addressed store, hash-verified

187
188
189class ResnetBlock2D(nn.Module):
190 r"""
191 A Resnet block.
192
193 Parameters:
194 in_channels (`int`): The number of channels in the input.
195 out_channels (`int`, *optional*, default to be `None`):
196 The number of output channels for the first conv2d layer. If None, same as `in_channels`.
197 dropout (`float`, *optional*, defaults to `0.0`): The dropout probability to use.
198 temb_channels (`int`, *optional*, default to `512`): the number of channels in timestep embedding.
199 groups (`int`, *optional*, default to `32`): The number of groups to use for the first normalization layer.
200 groups_out (`int`, *optional*, default to None):
201 The number of groups to use for the second normalization layer. if set to None, same as `groups`.
202 eps (`float`, *optional*, defaults to `1e-6`): The epsilon to use for the normalization.
203 non_linearity (`str`, *optional*, default to `"swish"`): the activation function to use.
204 time_embedding_norm (`str`, *optional*, default to `"default"` ): Time scale shift config.
205 By default, apply timestep embedding conditioning with a simple shift mechanism. Choose "scale_shift" for a
206 stronger conditioning with scale and shift.
207 kernel (`torch.Tensor`, optional, default to None): FIR filter, see
208 [`~models.resnet.FirUpsample2D`] and [`~models.resnet.FirDownsample2D`].
209 output_scale_factor (`float`, *optional*, default to be `1.0`): the scale factor to use for the output.
210 use_in_shortcut (`bool`, *optional*, default to `True`):
211 If `True`, add a 1x1 nn.conv2d layer for skip-connection.
212 up (`bool`, *optional*, default to `False`): If `True`, add an upsample layer.
213 down (`bool`, *optional*, default to `False`): If `True`, add a downsample layer.
214 conv_shortcut_bias (`bool`, *optional*, default to `True`): If `True`, adds a learnable bias to the
215 `conv_shortcut` output.
216 conv_2d_out_channels (`int`, *optional*, default to `None`): the number of channels in the output.
217 If None, same as `out_channels`.
218 """
219
220 def __init__(
221 self,
222 *,
223 in_channels: int,
224 out_channels: Optional[int] = None,
225 conv_shortcut: bool = False,
226 dropout: float = 0.0,
227 temb_channels: int = 512,
228 groups: int = 32,
229 groups_out: Optional[int] = None,
230 pre_norm: bool = True,
231 eps: float = 1e-6,
232 non_linearity: str = "swish",
233 skip_time_act: bool = False,
234 time_embedding_norm: str = "default", # default, scale_shift,
235 kernel: Optional[torch.Tensor] = None,
236 output_scale_factor: float = 1.0,
237 use_in_shortcut: Optional[bool] = None,
238 up: bool = False,
239 down: bool = False,
240 conv_shortcut_bias: bool = True,
241 conv_2d_out_channels: Optional[int] = None,
242 ):
243 super().__init__()
244 if time_embedding_norm == "ada_group":
245 raise ValueError(
246 "This class cannot be used with `time_embedding_norm==ada_group`, please use `ResnetBlockCondNorm2D` instead",

Callers 15

test_resnet_defaultMethod · 0.90
test_resnet_upMethod · 0.90
test_resnet_downMethod · 0.90
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
get_down_block_adapterFunction · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by 6

test_resnet_defaultMethod · 0.72
test_resnet_upMethod · 0.72
test_resnet_downMethod · 0.72