Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

训练过程中计算Recloss是不是有问题? #35

Closed
iloveOREO opened this issue Jul 8, 2022 · 1 comment
Closed

训练过程中计算Recloss是不是有问题? #35

iloveOREO opened this issue Jul 8, 2022 · 1 comment

Comments

@iloveOREO
Copy link

iloveOREO commented Jul 8, 2022

首先感谢大佬的开源实现, 给大佬点赞👍
对比了下大佬的训练代码和当前offical的实现还是有挺多不一样的.
这里训练用的数据集为CelebA, 原始使用的是VGGFace, VGGFace中有按人划分文件夹, CelebA中的都混在一起了. 这里在读取数据的时候, 用文件路径区分不同的人, 认为不同图片路径即为不同id, 感觉不是很恰当 (当然针对后续训练流程貌似也没大问题)
在 dataloader环节, 将是否相同图片标记了 data_type:

        data_type = self.type
        if self.count == self.bs:
            #self.type = 1 - type
            self.type = (self.type + 1) % 5  # better
            self.count = 0
        
        return img_id, img_att, latent_id, latent_att, data_type

然后在训练流程中, 将data_type给到了 forward的 for_G参数, 但是!!! 在forward过程中并没有实际用到, 导致针对不同图片换脸也计算了 RecLoss

        #G_ID
        img_fake_down = F.interpolate(img_fake, scale_factor=112/img_fake.shape[-1])
        latent_fake = self.netArc(img_fake_down)
        latent_fake = F.normalize(latent_fake, p=2, dim=1)
        loss_G_ID = (1 - self.cosin_metric(latent_fake, latent_id)) * self.opt.lambda_id
        #print('=====================G_ID========================')
        #print(loss_G_ID)

        #G_Rec
        loss_G_Rec = self.criterionRec(img_fake, img_att) * self.opt.lambda_rec

        # Only return the fake_B image if necessary to save BW
        return [self.loss_filter(loss_G_GAN, loss_G_GAN_Feat, loss_G_VGG, loss_G_ID, loss_G_Rec, loss_D_GP, loss_D_real, loss_D_fake),
                img_fake]

这样出来应该是不合适的吧? 会导致RecLoss失效?
请问我的理解是对的吗?
再次感谢大佬的开源贡献

@iloveOREO
Copy link
Author

不好意思, 是我理解错了, 这里的处理和offical的没有太大区别, offical在训练时有shuffle, 同样不会保证计算RecLoss的时候是完全相同的图

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant