MindSpore中Cifar数据集的读取及展示

MindSpore中对于常见数据及已经有现成API来进行处理,常见数据集包括:CelebA、Cifar100、Cifar10、Coco、ImageNet、Minist、VOC

下面以Cifar10数据集作为例子展示一下接口调用及数据的图片的展示

以下为官网提供的API的接口调用及解释:

class mindspore.dataset.Cifar10Dataset(dataset_dirusage=Nonenum_samples=Nonenum_parallel_workers=Noneshuffle=Nonesampler=Nonenum_shards=Noneshard_id=Nonecache=None)

A source dataset for reading and parsing Cifar10 dataset. This api only supports parsing Cifar10 file in binary version now. #用于读取和解析 Cifar10 数据集的源数据集,这个api现在只支持解析二进制版本的Cifar10文件

The generated dataset has two columns [image, label]. The tensor of column image is of the uint8 type. The tensor of column label is a scalar of the uint32 type # 生成的数据集有两列[image,label]。列图像的张量为uint8类型。列标签的张量是uint32类型的标量

接口调用及图片展示:

import mindspore.dataset as ds
from PIL import Image
import matplotlib.pyplot as plt

sampler = ds.SequentialSampler(num_samples=6)
dataset = ds.Cifar10Dataset(data_dir, sampler=sampler)

# 在数据集上创建迭代器,检索到的数据将是字典数据类型
for i, data in enumerate(dataset.create_dict_iterator()):
    print("Image shape: {}".format(data['image'].shape), ", Label {}".format(data['label']))
    image = data['image']
    image = image.asnumpy()  # mindspore.Tensor to numpy
    image = Image.fromarray(image)
    # plt
    plt.subplot(2, 3, i + 1)
    plt.imshow(image)
    plt.title(f"{i + 1}", fontsize=6)
    plt.xticks([])
    plt.yticks([])

plt.show()

结果展示:

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值