According to the way you load the data, there are two Situation

#Situation 1:
trainset = torchvision.datasets.CIFAR10(root=’./data’, train=True, download=True, transform=transform_train)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=128, shuffle=False, num_workers=2)

img = trainloader.dataset.train_data
labels = trainloader.dataset.train_labels

#Situation 2:
trainset    = torchvision.datasets.ImageFolder(root=’./train/train’, transform=transform_train)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=64, shuffle=True, num_workers=2)

data   = trainset.imgs
img    =[item[0] for item in data]
labels =[item[1] for item in data]