MCPcopy Create free account
hub / github.com/dek924/PerX2CT / forward

Method forward

taming/modules/diffusionmodules/model.py:295–339  ·  view source on GitHub ↗
(self, x, t=None)

Source from the content-addressed store, hash-verified

293
294
295 def forward(self, x, t=None):
296 #assert x.shape[2] == x.shape[3] == self.resolution
297
298 if self.use_timestep:
299 # timestep embedding
300 assert t is not None
301 temb = get_timestep_embedding(t, self.ch)
302 temb = self.temb.dense[0](temb)
303 temb = nonlinearity(temb)
304 temb = self.temb.dense[1](temb)
305 else:
306 temb = None
307
308 # downsampling
309 hs = [self.conv_in(x)]
310 for i_level in range(self.num_resolutions):
311 for i_block in range(self.num_res_blocks):
312 h = self.down[i_level].block[i_block](hs[-1], temb)
313 if len(self.down[i_level].attn) > 0:
314 h = self.down[i_level].attn[i_block](h)
315 hs.append(h)
316 if i_level != self.num_resolutions-1:
317 hs.append(self.down[i_level].downsample(hs[-1]))
318
319 # middle
320 h = hs[-1]
321 h = self.mid.block_1(h, temb)
322 h = self.mid.attn_1(h)
323 h = self.mid.block_2(h, temb)
324
325 # upsampling
326 for i_level in reversed(range(self.num_resolutions)):
327 for i_block in range(self.num_res_blocks+1):
328 h = self.up[i_level].block[i_block](
329 torch.cat([h, hs.pop()], dim=1), temb)
330 if len(self.up[i_level].attn) > 0:
331 h = self.up[i_level].attn[i_block](h)
332 if i_level != 0:
333 h = self.up[i_level].upsample(h)
334
335 # end
336 h = self.norm_out(h)
337 h = nonlinearity(h)
338 h = self.conv_out(h)
339 return h
340
341
342class Encoder(nn.Module):

Callers

nothing calls this directly

Calls 2

get_timestep_embeddingFunction · 0.70
nonlinearityFunction · 0.70

Tested by

no test coverage detected