MCPcopy Create free account
hub / github.com/DPS2022/diffusion-posterior-sampling / forward

Method forward

guided_diffusion/unet.py:705–734  ·  view source on GitHub ↗

Apply the model to an input batch. :param x: an [N x C x ...] Tensor of inputs. :param timesteps: a 1-D batch of timesteps. :param y: an [N] Tensor of labels, if class-conditional. :return: an [N x C x ...] Tensor of outputs.

(self, x, timesteps, y=None)

Source from the content-addressed store, hash-verified

703 self.output_blocks.apply(convert_module_to_f32)
704
705 def forward(self, x, timesteps, y=None):
706 """
707 Apply the model to an input batch.
708
709 :param x: an [N x C x ...] Tensor of inputs.
710 :param timesteps: a 1-D batch of timesteps.
711 :param y: an [N] Tensor of labels, if class-conditional.
712 :return: an [N x C x ...] Tensor of outputs.
713 """
714 assert (y is not None) == (
715 self.num_classes is not None
716 ), "must specify y if and only if the model is class-conditional"
717
718 hs = []
719 emb = self.time_embed(timestep_embedding(timesteps, self.model_channels))
720
721 if self.num_classes is not None:
722 assert y.shape == (x.shape[0],)
723 emb = emb + self.label_emb(y)
724
725 h = x.type(self.dtype)
726 for module in self.input_blocks:
727 h = module(h, emb)
728 hs.append(h)
729 h = self.middle_block(h, emb)
730 for module in self.output_blocks:
731 h = th.cat([h, hs.pop()], dim=1)
732 h = module(h, emb)
733 h = h.type(x.dtype)
734 return self.out(h)
735
736
737class SuperResModel(UNetModel):

Callers

nothing calls this directly

Calls 1

timestep_embeddingFunction · 0.85

Tested by

no test coverage detected