文章链接: http://blog.csdn.net/yhl_leo/article/details/71357097
之前发布的仿照CIFAR10数据集格式,制作自己的数据集 (C++版本),得到一些网友的关注,并且不断有网友在评论区或者私信里询问,怎样制作Python版本的。趁着下午有点闲时间,把制作方法整理发布在这里,希望对大家有所帮助。
源码地址GitHub: yhlleo/cifar10Dataset
关于python 版本的CIFAR10的数据格式,官网上已经介绍:
data – a 10000x3072 numpy array of uint8s. Each row of the array stores a 32x32 colour image. The first 1024 entries contain the red channel values, the next 1024 the green, and the final 1024 the blue. The image is stored in row-major order, so that the first 32 entries of the array are the red channel values of the first row of the image.
labels – a list of 10000 numbers in the range 0-9. The number at index i indicates the label of the ith image in the array data.
因此,想要制作自己的数据集,只需要把data, label准备好就可以,另外,我们可以读取cifar10存储好的文件,查看其数据格式,以data_batch_1为例(可以通过cifar10_read.py读取):
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
很明显,python版本存储成了一个dict,其中key包括:
data, 存放图像数据文件,是一个nx3072的数组;labels, 存放图像对应的label,是一个nx1的数组;batch_label, 说明信息;filenames, 文件名列表。
详细的代码内容,可以查看实现代码,另外demo.py中提供了测试数据,这里把读取的文件结果输出:
- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
跟官方数据的输出格式一致,虽然没有训练测试,但是理论上应该没问题,大家在测试的过程中,如果遇到问题,欢迎指出。

本文介绍如何创建符合Python版CIFAR10标准的数据集,包括数据组织方式及存储格式,附带源码并提供GitHub下载链接。

1万+

被折叠的 条评论
为什么被折叠?



