Can I find the number of specific numeric data in this MNIST training, test data?
import torchvision.datasets as dsets
import torchvision.transforms as transforms
import torch.nn.init
import torch.nn.functional as F


device = &quot;cuda&quot; if torch.cuda.is_available() else &quot;cpu&quot;
print(device)

learning_rate = 0.001
training_epochs = 15
batch_size = 100

mnist_train = dsets.MNIST(root='MNIST_data/', # Specify download path
                          train=True, # Specify True to download as training data
                          transform=transforms.ToTensor(), # Convert to tensor
                          download=True)

mnist_test = dsets.MNIST(root='MNIST_data/', # Specify download path
                         train=False, # If false is specified, download as test data
                         transform=transforms.ToTensor(), # Convert to tensor
                         download=True)


This is the part that loads the data of MNIST data classification code using CNN
In the book I refer to, it is said that you can see how many specific numeric data are in the training set and the test set by mentioning only that part.
For example, can you tell how many '5' data are in that training or test set?
Just knowing that you can access data tensors with mnist_train.train_data or mnist_train.train_labels, etc., I don't know how much I can think of how to know the number of specific numeric data. help

You can access the data and labels of the dataset, for either split, using the data and targets attributes respectively. So, for example, here you can access the training data and labels using mnist_train.data and mnist_train.labels respectively.
Since the targets attribute is a torch.Tensor for this dataset, you can count the number of instances of each target by using torch.bincount. Since there are 10 classes in total, the output will be a tensor of length 10, where the ith index specifies the number of data points of class i.
Example:
&gt;&gt;&gt; mnist_train = dsets.MNIST(root='MNIST_data/', train=True, transforms.ToTensor(), download=True)
&gt;&gt;&gt; mnist_train.targets
tensor([5, 0, 4,  ..., 5, 6, 8])
&gt;&gt;&gt; torch.bincount(mnist_train.targets, minlength=10)
tensor([5923, 6742, 5958, 6131, 5842, 5421, 5918, 6265, 5851, 5949])

You can see that class 5 has 5,421 data points in the training split.
