Explanation behind the calculation of accuracy in deep learning model
_, predicted = torch.max(output.data, 1)


On the first line above, it uses torch.max() to find all cases in output.data along the dimension - 1(i.e along each row). In addition, torch.max() returns (values, indices), so only the indices are stored in a variable called predicted while the values are not stored.

total_train += target.nelement()


The second line above just tracks the total size of the train set into a variable called total_train based on the number of elements in target

correct_train += predicted.eq(target.data).sum().item()


The third line above takes the predicted variable, which contains all indices of when the output is greater than 1, checks it against target.data, and sums up all items that are equal. In other words, it is counting how many of the predicted values are equal to the target data.