import numpy as npimport tensorflow as tfnp.random.seed(0)x = np.random.sample((11,2))# make a dataset from a numpy arrayprint(x) dataset = tf.data.Dataset.from_tensor_slices(x)dataset = dataset.shuffle(2) # 将数据打乱,数值越大,混乱程度越大dataset = dataset.batch(4
The Dataset.shuffle() implementation is designed for data that could be shuffled in memory; we're considering whether to add support for external-memory shuffles, but this is in the early stages. In case it works for you, here's the usual approach we
from torch.utils.data import Dataset from torch.utils.data import DataLoader from torch.utils.data import sampler import numpy as np import torch class OwnDataset(Dataset): def __init__(self,x,y): self.x = x self.y = y return def __getitem__(self,ind