here is my code.
class_correct = list(0. for i in range(3))
class_total = list(0. for i in range(3))
with torch.no_grad():
    for data in testloader:
        images, labels = data
        images = Variable(images)
        labels = Variable(labels)
        outputs = model(images)
        _, predicted = torch.max(outputs, 1)
        c = (predicted == labels).squeeze()
        for i in range(10):
            label = labels[i]
            class_correct[label] += c[i].item()
            class_total[label] += 1
            #print('Accuracy of %5s : %2f %%' % (classes[i], 100 * class_correct[i] / class_total[i]))


# =============================================================================
# for i in range(10):  
#     print('Accuracy of %5s : %2f %%' % (
#         classes[i], 100 * class_correct[i] / class_total[i]))