[转载] 深度学习数据集CIFAR-10和CIFAR-100高速下载(百度云)

转载出处:https://blog.csdn.net/mr_wanglv/article/details/79947640

文件内容:

cifar-10-binary.tar.gz

cifar-10-matlab.tar.gz

cifar-10-python.tar.gz

cifar-100-binary.tar.gz

cifar-100-matlab.tar.gz

cifar-100-python.tar.gz

将数据还原成.JPG格式图像的python代码

#encoding:utf-8
from scipy.misc import imsave
import numpy as np
 
#需要预先创建文件夹0-9
#0_29.jpg--文件名格式(来自哪个data_batch+第几个图像;0表示test_batch)
 
# 解压缩,返回解压后的字典
def unpickle(file):
    import pickle
    with open(file, 'rb') as fo:
        dict = pickle.load(fo, encoding='bytes')
    return dict
 
# 生成训练集图片,如果需要png格式,只需要改图片后缀名即可。
for j in range(1, 6):
    dataName = "data_batch_" + str(j)  # 读取当前目录下的data_batch12345文件,dataName其实也是data_batch文件的路径,本文和脚本文件在同一目录下。
    Xtr = unpickle(dataName)
    for i in Xtr:
        print(i)
    print(str(j-1))
    for i in range(0, 10000):
        img = np.reshape(Xtr[b'data'][i], (3, 32, 32))  # Xtr['data']为图片二进制数据
        img = img.transpose(1, 2, 0)  # 读取image
        picName = str(Xtr[b'labels'][i]) +'/'+ str(j)+'_'+str(i) + '.jpg'  #Xtr['labels']为图片的标签,值范围0-9,根据标签放入不同的文件夹
        imsave(picName, img)
    print(dataName + " loaded.")
 
print("test_batch is loading...")
# 生成测试集图片
testXtr = unpickle("test_batch")
for i in range(0, 10000):
    img = np.reshape(testXtr[b'data'][i], (3, 32, 32))
    img = img.transpose(1, 2, 0)
    picName=str(testXtr[b'labels'][i]) +'/'+'0_'+str(i) + '.jpg'  
    imsave(picName, img)
print("test_batch loaded.")

下载地址:https://pan.baidu.com/s/11hbfigdnQGzxB2EF4MALgQ

你可能感兴趣的:(程序猿)