Hello everyone, sorry for rookie question I’m starting to learn pytoch
this is my simple 1 layer linear classifier :
class Classifier(nn.Module):
    def __init__(self, in_dim ):
        super(Classifier, self).__init__()
        self.classify = nn.Linear(in_dim  , 1 )

    def forward(self, features ):

        final = torch.sigmoid ( self.classify(features) )
        return  final

I want the output to be probability, so ~1 means class 1 and ~0 means class 0
but I don’t know which loss function to use and how to calculate the accuracy in each epoch when I’m using batching ?
This is my current training loop but the loss is not correct, i feel like i need to change the code because this code is written for multi class classification, not a single output classification :
  

criterion = nn.CrossEntropyLoss()
optimizer = optim.Adam(model.parameters(), lr=0.001)
scheduler = optim.lr_scheduler.StepLR(optimizer, step_size=50, gamma=0.5)

net.train()


running_loss = 0
total_iters = len(trainloader)

for pos, (train_samples, labels) in zip(bar, trainloader):

    outputs = net(train_samples)

    loss = criterion(outputs, labels.float() )
    running_loss += loss.item()

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


running_loss = running_loss / total_iters

return running_loss