clcarwin / sphereface_pytorch

A PyTorch Implementation of SphereFace.
MIT License
714 stars 172 forks source link

How to init net parameters for sphere net when train from scratch #16

Closed wangzhenhua2015 closed 6 years ago

wangzhenhua2015 commented 6 years ago

Hi clcarwin,

I cannot see any code to initialize when create the net.
What initialization method should I choose when use Spherenet except in AngleLinear? Will the below method be ok for sphere net?

def weights_init(m):
    classname = m.__class__.__name__
    if classname.find('Conv') != -1:
        m.weight.data.normal_(0.0, 0.02)
        n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
        m.weight.data.normal_(0, math.sqrt(2. / n))
        if m.bias is not None:
            m.bias.data.zero_()
    elif classname.find('BatchNorm') != -1:
        m.weight.data.fill_(1)
        m.bias.data.zero_()
    elif classname.find('Linear') != -1:
        n = m.weight.size(1)
        m.weight.data.normal_(0, 0.01)
        m.bias.data.zero_()

thanks

clcarwin commented 6 years ago

Maybe the init is not necessary. It is needed to try by yourself.