zyainfal / One-Shot-Face-Swapping-on-Megapixels

One Shot Face Swapping on Megapixels.
Other
317 stars 41 forks source link

About calculate loss #17

Closed jo-dean closed 3 years ago

jo-dean commented 3 years ago

Hello,when i write the loss function, I found the pretrained model(such as ArcFace and HRnet),the Normalize is diff from HieRFE and stylegan2。 The mean and std in ArcFace is [0.485, 0.456, 0.406], [0.229, 0.224, 0.225], and in the HieRFE is [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]. How did you solve this problem? thank you!

zyainfal commented 3 years ago

We normalize images by [0.5, 0.5, 0.5], [0.5, 0.5, 0.5]. As the generated faces by StyleGAN2 should follow the distribution of normalized input faces, and when all the input of ArcFace, i.e. input faces and generated faces, is i.d.d., the identity loss calculated by ArcFace should be well-calibrated.

jo-dean commented 3 years ago

Thanks for your quick reply,I still can't understand what you mean very well. 1.did you mean generated faces by StyleGAN2 should normalized to [-1,1],cause the generated faces is Tensor format. I can process the input faces when load dataset, but the generated face, should I covert to RGB,then to tensor and normlize?

2.What is i.d.d.?

3.About the well-calibrated,can you tell me more detail?Does all the input of HRnet is same as ArcFace? thank you!

zyainfal commented 3 years ago
  1. You don't need to covert generated faces to RGB space. Use it directly for loss calculation.
  2. i.d.d. means identical and independent distribution.
  3. For example: by taking x as input image, x^ as generated face, the loss calculation process is
       x = normalize(x) # by [0.5,0.5,0.5], [0.5,0.5,0.5]
       latent = HieRFE(x)
       x^ = stylegan2(latent)
       identity_loss = 1 - cos (ArcFace(x), ArcFace(x^))
       landmark_loss = HRnet(x) - HRnet(x^)
jo-dean commented 3 years ago

I really appreciate you. I have been confused about the input preprocessing of the pretrained model before.