You can read about the CIFAR10 class frequencies on the offical website (they are already well knowned).
It’s much better to iterate over torch.utils.data.Dataset directly instead of DataLoader (you don’t need for your task batching, parallelization and other utilities that this class provides).
The entire error’s stack trace would be helpful for us to find the error so I’ll give you my, much more performant solution:
train_dataset = torchvision.datasets.CIFAR10(root='./data', train=True,
                                             download=True, transform=transform)

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()

It’s handy to use torch.bincount to count the frequencies in one step.