Hi,
Here is one way to do it:
from torchvision.datasets import CIFAR10
trainset = CIFAR10('./data', train=True, download=True)

# select classes you want to include in your subset
classes = torch.tensor([0, 1, 2, 3, 4])

# get indices that correspond to one of the selected classes
indices = (torch.tensor(trainset.targets)[..., None] == classes).any(-1).nonzero(as_tuple=True)[0]

# subset the dataset
data = torch.utils.data.Subset(trainset, indices)

# or maybe half of the datapoints of each of those classes
data2 = torch.utils.data.Subset(trainset, indices[::2])

# a random half of the datapoints of each of those classes
total = len(data)
data3 = torch.utils.data.random_split(data, [total//2, total-total//2])[0]