r""" A Resnet block that use normalization layer that incorporate conditioning information. 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 c
| 41 | |
| 42 | |
| 43 | class ResnetBlockCondNorm2D(nn.Module): |
| 44 | r""" |
| 45 | A Resnet block that use normalization layer that incorporate conditioning information. |
| 46 | |
| 47 | Parameters: |
| 48 | in_channels (`int`): The number of channels in the input. |
| 49 | out_channels (`int`, *optional*, default to be `None`): |
| 50 | The number of output channels for the first conv2d layer. If None, same as `in_channels`. |
| 51 | dropout (`float`, *optional*, defaults to `0.0`): The dropout probability to use. |
| 52 | temb_channels (`int`, *optional*, default to `512`): the number of channels in timestep embedding. |
| 53 | groups (`int`, *optional*, default to `32`): The number of groups to use for the first normalization layer. |
| 54 | groups_out (`int`, *optional*, default to None): |
| 55 | The number of groups to use for the second normalization layer. if set to None, same as `groups`. |
| 56 | eps (`float`, *optional*, defaults to `1e-6`): The epsilon to use for the normalization. |
| 57 | non_linearity (`str`, *optional*, default to `"swish"`): the activation function to use. |
| 58 | time_embedding_norm (`str`, *optional*, default to `"ada_group"` ): |
| 59 | The normalization layer for time embedding `temb`. Currently only support "ada_group" or "spatial". |
| 60 | kernel (`torch.Tensor`, optional, default to None): FIR filter, see |
| 61 | [`~models.resnet.FirUpsample2D`] and [`~models.resnet.FirDownsample2D`]. |
| 62 | output_scale_factor (`float`, *optional*, default to be `1.0`): the scale factor to use for the output. |
| 63 | use_in_shortcut (`bool`, *optional*, default to `True`): |
| 64 | If `True`, add a 1x1 nn.conv2d layer for skip-connection. |
| 65 | up (`bool`, *optional*, default to `False`): If `True`, add an upsample layer. |
| 66 | down (`bool`, *optional*, default to `False`): If `True`, add a downsample layer. |
| 67 | conv_shortcut_bias (`bool`, *optional*, default to `True`): If `True`, adds a learnable bias to the |
| 68 | `conv_shortcut` output. |
| 69 | conv_2d_out_channels (`int`, *optional*, default to `None`): the number of channels in the output. |
| 70 | If None, same as `out_channels`. |
| 71 | """ |
| 72 | |
| 73 | def __init__( |
| 74 | self, |
| 75 | *, |
| 76 | in_channels: int, |
| 77 | out_channels: int | None = None, |
| 78 | conv_shortcut: bool = False, |
| 79 | dropout: float = 0.0, |
| 80 | temb_channels: int = 512, |
| 81 | groups: int = 32, |
| 82 | groups_out: int | None = None, |
| 83 | eps: float = 1e-6, |
| 84 | non_linearity: str = "swish", |
| 85 | time_embedding_norm: str = "ada_group", # ada_group, spatial |
| 86 | output_scale_factor: float = 1.0, |
| 87 | use_in_shortcut: bool | None = None, |
| 88 | up: bool = False, |
| 89 | down: bool = False, |
| 90 | conv_shortcut_bias: bool = True, |
| 91 | conv_2d_out_channels: int | None = None, |
| 92 | ): |
| 93 | super().__init__() |
| 94 | self.in_channels = in_channels |
| 95 | out_channels = in_channels if out_channels is None else out_channels |
| 96 | self.out_channels = out_channels |
| 97 | self.use_conv_shortcut = conv_shortcut |
| 98 | self.up = up |
| 99 | self.down = down |
| 100 | self.output_scale_factor = output_scale_factor |
no outgoing calls
no test coverage detected
searching dependent graphs…