当前位置:网站首页>Mindspire series one loading image classification data set
Mindspire series one loading image classification data set
2022-06-28 18:48:00 【Cat chaser】
MindSpore It provides loading interfaces for most common datasets and standard format datasets , You can use it directly mindspore.dataset Data loading is performed by the corresponding dataset loading class in , Such as MNIST、CIFAR-10、CIFAR-100、VOC、COCO、ImageNet、CelebA、CLUE etc. , And industry standard data sets , Include MindRecord、TFRecord、Manifest etc. .
Common datasets loaded to cifar10 For example , First of all, will cifar10 Data sets are downloaded and extracted locally .
1、 load cifar10 Data sets :
DATA_DIR = "./cifar-10-batches-bin/"
sampler = ds.SequentialSampler(num_samples=5)
dataset = ds.Cifar10Dataset(DATA_DIR, sampler=sampler)
use create_dict_iterator Create data iterators to access data :
for data in dataset.create_dict_iterator():
print("Image shape: {}".format(data['image'].shape), ", Label: {}".format(data['label']))

2、 Load custom image classification dataset
Use mindspore Load custom image classification data , have access to mindspore.dataset.ImageFolderDataset Interface to load . Put images of the same category in the same folder , Different categories are distinguished by different folders , Pass in the parent directory of all categories ImageFolderDataset Interface ,mindspore The image data will be automatically loaded and the corresponding labels will be assigned according to different folders .


Here we use TinyImageNet As an example to load data . First , Use imageFolderDataset Interface incoming data path , adopt num_parallel_worker The number of data loading parallel threads can be set ,shuffle Whether the parameter setting disturbs the data order . In addition, we need to pass map Interface for image data preprocessing , Image preprocessing interface mindspore.dataset.vision.c_transforms, adopt c_transforms Image decoding is possible , Scaling normalization , Matrix transpose and other operations .
import mindspore
import mindspore.dataset as ds
import mindspore.dataset.vision.c_transforms as CV
import mindspore.dataset.transforms.c_transforms as C
from mindspore import dtype as mstype
def create_dataset(data_path, batch_size=24, c_transforms
repeat_num=1):
""" Define datasets """
parallel_mode = context.get_auto_parallel_context("parallel_mode")
if parallel_mode == context.ParallelMode.DATA_PARALLEL:
data_set = ds.ImageFolderDataset(data_path, num_parallel_def create_dataset(data_path, batch_size=24, repeat_num=1):
""" Define datasets """
data_set = ds.ImageFolderDataset(data_path, num_parallel_workers=8, shuffle=True)
image_size = [100, 100]
mean = [0.485 * 255, 0.456 * 255, 0.406 * 255]
std = [0.229 * 255, 0.224 * 255, 0.225 * 255]
trans = [
CV.Decode(),
CV.Resize(image_size),
CV.Normalize(mean=mean, std=std),
CV.HWC2CHW()
]
# To achieve data map mapping 、 Batch processing and data repetition
type_cast_op = C.TypeCast(mstype.int32)
data_set = data_set.map(operations=trans, input_columns="image", num_parallel_workers=8)
data_set = data_set.map(operations=type_cast_op, input_columns="label", num_parallel_workers=8)
data_set = data_set.batch(batch_size, drop_remainder=True)
data_set = data_set.repeat(repeat_num)
return data_set
Data iteration ,ImageFolderDataset adopt create_tuple_iterator() Interface iterates over the data set , One at a time batch The data of .
if __name__ == '__main__':
datapath = 'D:/Sources/Data/datasets/TinyImageNet/val'
ds = create_dataset(datapath, batch_size=8)
iterator = ds.create_tuple_iterator()
for item in iterator:
print(f'images:{mindspore.Tensor(item[0]).shape},labels:{item[1]}')

边栏推荐
- About Significance Tests
- 模块化操作
- 1 goal, 3 fields, 6 factors and 9 links of digital transformation
- 深入解析kubernetes中的选举机制
- 做跨境电商一定要学会用PRA软件,解放双手提高效率!
- [unity3d] emission (raycast) physical ray (Ray)
- Huawei cloud AOM released version 2.0, and three features appeared
- id门禁卡复制到手机_怎么把手机变成门禁卡 手机NFC复制门禁卡图文教程
- PCB线路板布局和布线都有哪些设计要求?
- 毕业设计-基于Unity的餐厅经营游戏的设计与开发(附源码、开题报告、论文、答辩PPT、演示视频,带数据库)
猜你喜欢

Analyzing the practical development of robot teaching

ONEFLOW source code parsing: automatic inference of operator signature

What are the design requirements for PCB layout and wiring?

Win 10创建一个gin框架的项目

use. NETCORE's own background job, which simply simulates producers and consumers' processing of request response data in and out of the queue

MindSpore系列一加载图像分类数据集

Professor Michael Wooldridge of Oxford University: how the AI community views neural networks in the past 40 years

1 invalid import format(s) Postman Collection Format v1 is no longer supported and can not be import
![[unity3d] camera follow](/img/11/6309450f2b3ef33df558104549dc4c.png)
[unity3d] camera follow

PCB线路板布局和布线都有哪些设计要求?
随机推荐
使用Karmada实现Helm应用的跨集群部署
微信小程序接入百度统计报错 Cannot read property ‘mtj‘ of undefined
C# 41. int与string互转
PMP怎么补考?补考费用是多少?
1 invalid import format(s) Postman Collection Format v1 is no longer supported and can not be import
闭包的理解
Upload file list (repeated file names are marked with brackets)
Lumiprobe非荧光叠丨氮化物研究丨3-叠丨氮丙醇
19.2 容器分类、array、vector容器精解
原生实现.NET5.0+ 自定义日志
MindSpore系列一加载图像分类数据集
Openfire 3.8.2集群配置
Lumiprobe非荧光炔烃研究丨DBCO NHS 酯
Lumiprobe丨Lumizol RNA 提取试剂解决方案
Steam education to break the barriers between disciplines
电子商务盛行,怎么提高商店转换率?
手动备份和还原DHCP服务器
进阶高级-业务事务设计 开发入门
注意!PMP紧急缓考今天就截止了!
About Covariance and Correlation(协方差和相关)