I’m trying to implement a learnable bias layer which would add a constant value to every element of the input. Learnable bias layer exists in lasagne but I was unable to find such a layer in pytorch. I initialized bias as a parameter but the value is not changing. Is this the right way to do it? -
 class Net(nn.Module):
     def __init__(self):
       super(Net, self).__init__()
       self.bias = nn.Parameter(torch.ones(1))
       self.conv1 = nn.Conv2d(1, 1, kernel_size=1,  bias=False)

def forward(self,x):
    x = self.conv1(x)
    bias_matrix = Variable(torch.ones((x.size()))*self.bias.cpu().data[0]).cuda()
    x =  x.add(bias_matrix)
    print self.bias
    return x