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)
| 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 | |
| 737 | class SuperResModel(UNetModel): |
nothing calls this directly
no test coverage detected