MCPcopy Create free account
hub / github.com/294coder/Dif-PAN / __init__

Method __init__

models/unet_model_google.py:212–323  ·  view source on GitHub ↗
(
        self,
        in_channel=6,
        out_channel=3,
        inner_channel=32,
        norm_groups=32,
        channel_mults=(1, 2, 4, 8, 8),
        attn_res=(8,),
        res_blocks=3,
        dropout=0,
        with_time_emb=True,
        image_size=128,
        self_condition=False,
    )

Source from the content-addressed store, hash-verified

210
211class UNet(nn.Module):
212 def __init__(
213 self,
214 in_channel=6,
215 out_channel=3,
216 inner_channel=32,
217 norm_groups=32,
218 channel_mults=(1, 2, 4, 8, 8),
219 attn_res=(8,),
220 res_blocks=3,
221 dropout=0,
222 with_time_emb=True,
223 image_size=128,
224 self_condition=False,
225 ):
226 super().__init__()
227
228 if with_time_emb:
229 time_dim = inner_channel
230 self.time_mlp = nn.Sequential(
231 TimeEmbedding(inner_channel),
232 nn.Linear(inner_channel, inner_channel * 4),
233 Swish(),
234 nn.Linear(inner_channel * 4, inner_channel),
235 )
236 else:
237 time_dim = None
238 self.time_mlp = None
239
240 num_mults = len(channel_mults)
241 pre_channel = inner_channel
242 feat_channels = [pre_channel]
243 now_res = image_size
244 if self_condition:
245 in_channel += out_channel
246 downs = [nn.Conv2d(in_channel, inner_channel, kernel_size=3, padding=1)]
247 for ind in range(num_mults):
248 is_last = ind == num_mults - 1
249 use_attn = now_res in attn_res
250 print(f"unet init: use attn size: {now_res}")
251 channel_mult = inner_channel * channel_mults[ind]
252 for _ in range(0, res_blocks):
253 downs.append(
254 ResnetBlocWithAttn(
255 pre_channel,
256 channel_mult,
257 time_emb_dim=time_dim,
258 norm_groups=norm_groups,
259 dropout=dropout,
260 with_attn=use_attn,
261 attn_guide=True,
262 )
263 )
264 feat_channels.append(channel_mult)
265 pre_channel = channel_mult
266 if not is_last:
267 downs.append(Downsample(pre_channel))
268 feat_channels.append(pre_channel)
269 now_res = now_res // 2

Callers 9

__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
__init__Method · 0.45
__init__Method · 0.45

Calls 7

TimeEmbeddingClass · 0.85
SwishClass · 0.70
ResnetBlocWithAttnClass · 0.70
DownsampleClass · 0.70
UpsampleClass · 0.70
BlockClass · 0.70
defaultFunction · 0.70

Tested by

no test coverage detected