I don’t know, how train_transform is defined, but your posted code works fine after removing the data loading part:
class CreateDataset(Dataset):
    def __init__(self, data, labels, transform=None):
        self.data = data
        self.transform = transform
        self.labels = labels
        
    def __len__(self):
        return len(self.data)
        
    def __getitem__(self, index):
        image = self.data[index]
        label = self.labels[index]
        return image, label
    
dataset = CreateDataset(
    data=torch.randn(100, 3, 224, 224),
    labels=torch.randint(0, 10, (100,)))

loader = DataLoader(dataset, batch_size=5)
for data, target in loader:
    print(target)

If you still get stuck, please post another executable code snippet, to reproduce the error.
Since I don’t have your data on my machine, I would have to remove some parts such as the data loading from the code.