Initalize the weights of nn.ConvTranspose2d
how shoud I initalize  the weights of nn.ConvTranspose2d ? like nn.Conv2d? is this any special for Pytorch <SCODE>for m in self.modules():
    if isinstance(m, nn.Conv2d):
        n = m.kernel_size[0] * m.kernel_size[1] * m.out_channels
        m.weight.data.normal_(0, math.sqrt(2. / n))
    elif isinstance(m, nn.BatchNorm2d):
        m.weight.data.fill_(1)
        m.bias.data.zero_()
<ECODE> infer :  the bias will automatically initialize with random value . is that right? <SCODE>def weights_initG(m):
    for p in m.modules():
        if isinstance(p,nn.Conv2d):
            n = p.kernel_size[0] * p.kernel_size[1] * p.out_channels
            p.weight.data.normal_(0, math.sqrt(2. / n))
        elif isinstance(p,nn.BatchNorm2d):
            p.weight.data.normal_(1.0, 0.02)
            p.bias.data.fill_(0)
        elif isinstance(p,nn.ConvTranspose2d):
            n=p.kernel_size[1]
            factor = (n+1)//2
            if n%2 ==1:
                center = factor - 1
            else :
                center = factor -0.5
            og = np.ogrid[:n,:n]
            weights_np=(1-abs(og[0]-center)/factor)* (1-abs(og[1]-center)/ factor)
            p.weight.data.copy_(torch.from_numpy(weights_np))
<ECODE>
huxc_ustc
<SCODE>def weights_init(m):
    classname = m.__class__.__name__
    if classname.find('Conv') != -1:
        m.weight.data.normal_(0.0, 0.02)
    elif classname.find('BatchNorm') != -1:
        m.weight.data.normal_(1.0, 0.02)
        m.bias.data.fill_(0)

netG.apply(weights_init)
<ECODE> it should work.
chenyuntc
david-leon
apaszke
acgtyrant
bille_du
<SCODE>m.weight.data.normal_(1.0, 0.02).clamp_(min=0,max=2)
<ECODE>
chenyuntc
ok，thank you！by the way，if I want to clamp [-1, -0.1] and [0.1,1] 。How to operate？
bille_du
<SCODE>a.clamp_(min=-1,max=1)
a[a.abs()<0.1]=t.sign(a[a.abs()<0.1])*0.1
<ECODE>
chenyuntc
bolt25
<SCODE>lin = nn.Linear(10, 10, bias=False)

with torch.no_grad():
    lin.weight.normal_(0.0, 1.0)
<ECODE>
ptrblck
bolt25
ptrblck