当前位置:网站首页>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]}')

边栏推荐
- An in-depth analysis of the election mechanism in kubernetes
- Steam education to break the barriers between disciplines
- 实时Transformer:美团在单图像深度估计上的研究
- Is it reliable to open an account for the shares of Oriental Wealth software? Where is safe to open an account
- 1 invalid import format(s) Postman Collection Format v1 is no longer supported and can not be import
- Chapter 2 processing files, cameras and GUI Cameo applications
- [unity3d] camera follow
- 内存抖动
- 【软件测试】2022年普通高等学校招生全国统一考试
- leetcode 1423. Maximum Points You Can Obtain from Cards(从牌中能得到的最大点数和)
猜你喜欢
随机推荐
C语言指针的一些易错点
About Statistical Distributions
About Statistical Distributions
用户网络模型与QoE
Michael Wooldridge, professeur à l'Université d'Oxford: comment la communauté de l'IA voit les réseaux neuronaux depuis près de 40 ans
Shell脚本批量修改文件目录权限
1 invalid import format(s) Postman Collection Format v1 is no longer supported and can not be import
Object tracking using tracker in opencv
Qt 中 QObjectCleanupHandler 使用总结
手动备份和还原DHCP服务器
sqrt()函数的详解和用法「建议收藏」
C# 41. Int to string
Upload file list (repeated file names are marked with brackets)
运筹学note
use. NETCORE's own background job, which simply simulates producers and consumers' processing of request response data in and out of the queue
上传文件列表(文件名重复加括号标识)
数字化转型的1个目标,3大领域,6大因素和9个环节
Advanced technology management - how managers communicate performance and control risks
curl: (56) Recv failure: Connection reset by peer
PCB线路板布局和布线都有哪些设计要求?








