MCPcopy Index your code
hub / github.com/huggingface/diffusers / __init__

Method __init__

src/diffusers/models/resnet.py:73–146  ·  view source on GitHub ↗
(
        self,
        *,
        in_channels: int,
        out_channels: int | None = None,
        conv_shortcut: bool = False,
        dropout: float = 0.0,
        temb_channels: int = 512,
        groups: int = 32,
        groups_out: int | None = None,
        eps: float = 1e-6,
        non_linearity: str = "swish",
        time_embedding_norm: str = "ada_group",  # ada_group, spatial
        output_scale_factor: float = 1.0,
        use_in_shortcut: bool | None = None,
        up: bool = False,
        down: bool = False,
        conv_shortcut_bias: bool = True,
        conv_2d_out_channels: int | None = None,
    )

Source from the content-addressed store, hash-verified

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
101 self.time_embedding_norm = time_embedding_norm
102
103 if groups_out is None:
104 groups_out = groups
105
106 if self.time_embedding_norm == "ada_group": # ada_group
107 self.norm1 = AdaGroupNorm(temb_channels, in_channels, groups, eps=eps)
108 elif self.time_embedding_norm == "spatial":
109 self.norm1 = SpatialNorm(in_channels, temb_channels)
110 else:
111 raise ValueError(f" unsupported time_embedding_norm: {self.time_embedding_norm}")
112
113 self.conv1 = nn.Conv2d(in_channels, out_channels, kernel_size=3, stride=1, padding=1)
114
115 if self.time_embedding_norm == "ada_group": # ada_group
116 self.norm2 = AdaGroupNorm(temb_channels, out_channels, groups_out, eps=eps)
117 elif self.time_embedding_norm == "spatial": # spatial
118 self.norm2 = SpatialNorm(out_channels, temb_channels)
119 else:
120 raise ValueError(f" unsupported time_embedding_norm: {self.time_embedding_norm}")
121
122 self.dropout = torch.nn.Dropout(dropout)
123
124 conv_2d_out_channels = conv_2d_out_channels or out_channels
125 self.conv2 = nn.Conv2d(out_channels, conv_2d_out_channels, kernel_size=3, stride=1, padding=1)
126
127 self.nonlinearity = get_activation(non_linearity)
128
129 self.upsample = self.downsample = None
130 if self.up:

Callers

nothing calls this directly

Calls 6

AdaGroupNormClass · 0.85
SpatialNormClass · 0.85
get_activationFunction · 0.85
Upsample2DClass · 0.85
Downsample2DClass · 0.85
__init__Method · 0.45

Tested by

no test coverage detected