Why aren't the parameters in the class learned?

Viewed 22
class sa(nn.Module):
def __init__(self, inp_dim, out_dim, stride=1, column=3, mod_len=2, with_bn=True):
    super(sa, self).__init__()
    dev = torch.device('cuda')
    self.layers = nn.ModuleList(
                                    nn.ModuleList(
                                        convolution(i*2+3, inp_dim if l == 0 else out_dim, out_dim, stride) 
                                        for i in range(column)
                                    )
                                    for l in range(mod_len)
                                )
    
    self.in_weight = torch.randn((column), requires_grad=True, dtype=torch.float32).to(dev)  
    self.skip = nn.Sequential(
                    nn.Conv2d(inp_dim,out_dim,(1,1),stride=(stride,stride),bias=False),
                    nn.BatchNorm2d(out_dim)
                )
    self.relu = nn.ReLU(inplace=True)
    self.sig = nn.Sigmoid()

def forward(self,x):
    skip = self.skip(x)
    iw = self.sig(self.in_weight)
    feat = torch.stack([in_w*x for in_w in iw],dim=0)
    .
    .
    .

I made a class like the one above and proceeded with learning. However, no matter how many epochs are run, the value of self.in_weight does not change. Please help me

0 Answers
Related