LTH14 / rcg

PyTorch implementation of RCG https://arxiv.org/abs/2312.03701
MIT License
785 stars 36 forks source link

对于下游任务(有条件生成、无条件生成、语义编辑(插值))来说,我应该训练的是有条件“pixel generator”呢还是无条件的呢? #29

Closed mapengsen closed 3 months ago

mapengsen commented 4 months ago

作者您好,您的文章做的很好。 我想问一下对于“pixel generator”的训练过程,这个“pixel generator”是应该训练有条件的呢还是无条件的呢?

我看到在DiT的训练中

    def forward(self, x, t, y, rep=None):
        """
        Forward pass of DiT.
        x: (N, C, H, W) tensor of spatial inputs (images or latent representations of images)
        t: (N,) tensor of diffusion timesteps
        y: (N,) tensor of class labels
        """
        x = self.x_embedder(x) + self.pos_embed  # (N, T, D), where T = H * W / patch_size ** 2
        t = self.t_embedder(t)                   # (N, D)
        y = self.y_embedder(y, self.training)    # (N, D)
        # rep cond
        if rep is not None:
            # 1、get the CFG mixture rep
            if self.training:
                drop_rep_mask = torch.rand(x.size(0)) < self.rep_dropout_prob
                drop_rep_mask = drop_rep_mask.unsqueeze(-1).cuda().float()
                rep = drop_rep_mask * self.fake_latent + (1 - drop_rep_mask) * rep
            rep = self.rep_embedder(rep)
            c = t + rep
        else:
            c = t + y  # (N, D)

        for block in self.blocks:
            x = block(x, c)                      # (N, T, D)
        x = self.final_layer(x, c)                # (N, T, patch_size ** 2 * out_channels)
        x = self.unpatchify(x)                   # (N, out_channels, H, W)
        return x

是并没有使用标签y的信息(也就意味着训练的是无条件生成模型?)

我想知道对于下游任务(有条件生成、无条件生成、语义编辑(插值))来说,我应该训练的是有条件“pixel generator”呢还是无条件的呢?

谢谢作者

LTH14 commented 4 months ago

感谢您的关注!在RCG的框架里,pixel generator都是“无条件生成”,或者说只基于representation进行生成。如果要进行有条件生成的下游任务,我们的做法是训练一个有条件生成的representation generator。这样的一个好处是可以让pixel generator在大规模无监督数据集上进行训练,再用小规模的有监督数据集进行有条件生成的训练。

LTH14 commented 4 months ago

在这个代码框架里我们也保留了“有条件生成”的baseline,比如class-conditional generation(rep为None,只输入y)。但是RCG是不需要训练有条件生成的pixel generator的。

mapengsen commented 4 months ago

说的很清晰,非常感谢您的耐心回复