I would like to do binary classification with softmax. Am I calculating training accuracy in the code below wrong?
I am new to Pytorch and it is very strange I am getting accuracy above 100
correct = 0
train_loss = []
model.train()
for epoch in range(epochs):
for xb, yb in train_dl:
y_pred = model(xb)
loss = loss_func(y_pred, yb)
optimizer.zero_grad()
loss.backward()
optimizer.step()
train_loss.append(loss.item())
_,y_pred_ = torch.max(y_pred, dim = 1)
correct += (y_pred_ == yb).sum()
acc_ = 100 * correct / len(x_tensor)
print(correct)
print("Accuracy = {}".format(acc_))
print('Last iteration loss value: '+str(loss.item()))
thanks in advance