mariosasko:

labels = torch.tensor([instance[1] for instance in train_dataset])
class_freq = labels.bincount()

classes = ['plane', 'car', 'bird', 'cat','deer', 'dog', 
           'frog', 'horse', 'ship', 'truck']

indexes = np.arange(len(classes))
width = 0.3
plt.bar(indexes, class_freq.numpy(), align='edge', width=width)
plt.xticks(indexes + width * 0.5, classes)
plt.show()



A clean and really much more better solution ! Thank you .
But I really want to understand why the error occurred,and why exactly the index k is out of bounds? Is it because the first loop does not pass to the next image data in the trainloader_classes?