從PyTorch DataLoader讀取隨機的1個Sample

Random sample from DataLoader

example = next(iter(dataloader))[0]

Random sample from Dataset

idx = torch.randint(len(dataset), (1,))
example = dataset[idx]