You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test2.py 608 B

123456789101112131415161718192021
  1. import torch
  2. # from torch.utils.data import DataLoader, Dataset
  3. import paddle
  4. from paddle.io import Dataset, DataLoader
  5. paddle.device.set_device("cpu")
  6. class NormalDataset(Dataset):
  7. def __init__(self, num_of_data=1000):
  8. self.num_of_data = num_of_data
  9. self._data = list(range(num_of_data))
  10. def __len__(self):
  11. return self.num_of_data
  12. def __getitem__(self, item):
  13. return self._data[item]
  14. dataset = NormalDataset(20)
  15. dataloader = DataLoader(dataset, batch_size=2, use_buffer_reader=False)
  16. for i, b in enumerate(dataloader):
  17. print(b)
  18. if i >= 2:
  19. break