If you have a folder structure similar to the imagenet one (each folder represents a class, and has images in it), then you can directly use the torchvision.dataset.ImageFolder, and no need to go through the torch.utils.data.TensorDataset. Here is an example 63.