MCPcopy Create free account
hub / github.com/ToTheBeginning/PuLID / __init__

Method __init__

flux/modules/autoencoder.py:110–157  ·  view source on GitHub ↗
(
        self,
        resolution: int,
        in_channels: int,
        ch: int,
        ch_mult: list[int],
        num_res_blocks: int,
        z_channels: int,
    )

Source from the content-addressed store, hash-verified

108
109class Encoder(nn.Module):
110 def __init__(
111 self,
112 resolution: int,
113 in_channels: int,
114 ch: int,
115 ch_mult: list[int],
116 num_res_blocks: int,
117 z_channels: int,
118 ):
119 super().__init__()
120 self.ch = ch
121 self.num_resolutions = len(ch_mult)
122 self.num_res_blocks = num_res_blocks
123 self.resolution = resolution
124 self.in_channels = in_channels
125 # downsampling
126 self.conv_in = nn.Conv2d(in_channels, self.ch, kernel_size=3, stride=1, padding=1)
127
128 curr_res = resolution
129 in_ch_mult = (1,) + tuple(ch_mult)
130 self.in_ch_mult = in_ch_mult
131 self.down = nn.ModuleList()
132 block_in = self.ch
133 for i_level in range(self.num_resolutions):
134 block = nn.ModuleList()
135 attn = nn.ModuleList()
136 block_in = ch * in_ch_mult[i_level]
137 block_out = ch * ch_mult[i_level]
138 for _ in range(self.num_res_blocks):
139 block.append(ResnetBlock(in_channels=block_in, out_channels=block_out))
140 block_in = block_out
141 down = nn.Module()
142 down.block = block
143 down.attn = attn
144 if i_level != self.num_resolutions - 1:
145 down.downsample = Downsample(block_in)
146 curr_res = curr_res // 2
147 self.down.append(down)
148
149 # middle
150 self.mid = nn.Module()
151 self.mid.block_1 = ResnetBlock(in_channels=block_in, out_channels=block_in)
152 self.mid.attn_1 = AttnBlock(block_in)
153 self.mid.block_2 = ResnetBlock(in_channels=block_in, out_channels=block_in)
154
155 # end
156 self.norm_out = nn.GroupNorm(num_groups=32, num_channels=block_in, eps=1e-6, affine=True)
157 self.conv_out = nn.Conv2d(block_in, 2 * z_channels, kernel_size=3, stride=1, padding=1)
158
159 def forward(self, x: Tensor) -> Tensor:
160 # downsampling

Callers 7

__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45
__init__Method · 0.45

Calls 3

ResnetBlockClass · 0.85
DownsampleClass · 0.85
AttnBlockClass · 0.85

Tested by

no test coverage detected