cifar10数据集使⽤python转换为图⽚以及分类保存
感想:⽹上查了⼀圈,准备想转换为图⽚,发现写的是什么玩意,保存图⽚都不是按照类别保存的,现在我详细说明⼀下。
下⾯解压后除了train全部是下载后解压的。最后保存在train⽂件夹下⾯
import os
# from scipy.misc import imsave
from imageio import imsave
def unpickle(file):
import pickle
with open(file, 'rb') as fo:
dict = pickle.load(fo, encoding='bytes')
import picklereturn dict
filename = 'D:/cifar-10-python/cifar-10-batches-py-img/' #图⽚的路径
meta = unpickle(filename + '/a')
label_name = meta[b'label_names']
for i in range(len(label_name)):
file = label_name[i].decode()
path = 'D:/cifar-10-python/cifar-10-batches-py-img/train/' + file
isExist = ists(path)
if not isExist:
os.makedirs(path)
for i in range(1, 6):
content = unpickle(filename + '/data_batch_' + str(i)) #解压后的每个data_batch_
print('')
print(content.keys())
print('tranfering data_batch' + str(i))
for j in range(10000):
img = content[b'data'][j]
img = shape(3, 32, 32)
img = anspose(1, 2, 0)
img_name = 'D:/cifar-10-python/cifar-10-batches-py-img/train/' + label_name[content[b'labels'][j]].decode() + '/batch_' + str(i) + '_num_' + str(            j) + '.jpg'
imsave(img_name, img)
最后结果:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。