Hi Guys,
I am trying to do multi-class image classification.
I am trying to debug my network for potential bugs so training and validating are on the same subset of data. Logically, the training and validation loss should decrease and then saturate which is happening but also, it should give 100% or a very large accuracy on the valid set( As it is same as of training set), but it is giving 0% accuracy.
So I am wondering whether my calculation of accuracy is correct or not? Below is my code, could you please check and point me if there are any bugs which I am not able to figure it out.
    model.eval()
    for batch_idx, (data, target) in enumerate(loader['valid']):
        # move to GPU
        if torch.cuda.is_available():
            data, target = data.cuda(), target.cuda()
        # update the average validation loss
        output = model(data).squeeze()
        output = torch.unsqueeze(output, 0)
        loss = criterion(output, target)   # changes
        valid_loss += ((1 / (batch_idx + 1)) * ((loss.data) - valid_loss))
        pred = output.data.max(1, keepdim=True)[0]
        correct += np.sum(np.squeeze(pred.eq(target.data.view_as(pred)).cpu().numpy()))
        total += data.size(0)
    accuracy = 100. * (correct/total)
    print('Epoch: {} \tTraining Loss: {:.6f} \tValidation Loss: {:.6f} \t Validation Accuracy: {:.6f}'.format(
        epoch,
        train_loss,
        valid_loss,
        accuracy
        ))