microsoft / Deep3DFaceReconstruction

Accurate 3D Face Reconstruction with Weakly-Supervised Learning: From Single Image to Image Set (CVPRW 2019)
MIT License
2.18k stars 443 forks source link

Why did you multiply 2 in your code when calculating Regulation_loss #147

Open havefunbb opened 3 years ago

havefunbb commented 3 years ago

It's not necessary to multiply 2 in the code, if you really want to increase the Regulation_loss you could increase the loss weight in option.py. But why did you do this in your code?

havefunbb commented 3 years ago
def Regulation_loss(id_coeff,ex_coeff,tex_coeff,opt):
    w_ex = opt.w_ex
    w_tex = opt.w_tex

    regulation_loss = tf.nn.l2_loss(id_coeff) + w_ex * tf.nn.l2_loss(ex_coeff) + w_tex * tf.nn.l2_loss(tex_coeff)
    regulation_loss = 2 * regulation_loss/ tf.cast(tf.shape(id_coeff)[0],tf.float32)      # *2  why???

    return regulation_loss 
YuDeng commented 3 years ago

tf.nn.l2_loss actually calculates sum(x**2)/2. We multiply it with 2 in order to compensate for the division inside the tf function.

havefunbb commented 3 years ago

OK,thanks