Sorry I’m a newbie.
Trying to solve a classification problem with pytorch. But the predictions always turns into all zeroes.
Please can someone help.
num_classes = 2
input_size = 3
hidden_size = 4
num_epochs = 5

class Net(Module):
    def __init__(self, input_size, hidden_size, num_classes):
        super().__init__()

        self.l1 = Linear(input_size, hidden_size)
        self.l2 = Linear(hidden_size, num_classes)
        self.sig = Tanh()

    def forward(self, x):
        out = self.l1(x)
        out = self.sig(out)
        out = self.l2(out)
        return F.log_softmax(out)



nn = Net(input_size, hidden_size, num_classes)
optimizer = optim.Adam(nn.parameters(), lr=0.001)

for epoch in range(100):
    output = nn(x)
    _, y_pred = output.max(1)

    print('target',str(y[:4].view(1,-1)).split('\n')[1])
    print('predct',str(y_pred[:4].view(1,-1)).split('\n')[1])

    loss = F.nll_loss(output,y)
    print(loss.data[0])

    optimizer.zero_grad()
    loss.backward()
    optimizer.step()

for i,j in zip(y[:20],y_pred[:20]):
    print(i.data[0],j.data[0])