参考地址:
https://www.mindspore.cn/tutorial/zh-CN/r1.2/dataset.html
========================================================
数据集下载:
mkdir -p ./datasets/MNIST_Data/train ./datasets/MNIST_Data/test wget -NP ./datasets/MNIST_Data/train https://mindspore-website.obs.myhuaweicloud.com/notebook/datasets/mnist/train-labels-idx1-ubyte wget -NP ./datasets/MNIST_Data/train https://mindspore-website.obs.myhuaweicloud.com/notebook/datasets/mnist/train-images-idx3-ubyte wget -NP ./datasets/MNIST_Data/test https://mindspore-website.obs.myhuaweicloud.com/notebook/datasets/mnist/t10k-labels-idx1-ubyte wget -NP ./datasets/MNIST_Data/test https://mindspore-website.obs.myhuaweicloud.com/notebook/datasets/mnist/t10k-images-idx3-ubyte tree ./datasets/MNIST_Data
顺序读取N个样本:
import mindspore.dataset as ds from mindspore import dtype as mstype DATA_DIR = "./datasets/MNIST_Data/train" sampler = ds.SequentialSampler(num_samples=3) dataset = ds.MnistDataset(DATA_DIR, sampler=sampler) for data in dataset.create_dict_iterator(): print("Image shape: {}".format(data['image'].shape), ", Label: {}".format(data['label'])) print(data['label'], "\t", data['label'].astype(mstype.float32))