CIFAR-10图像事物识别数据集

作者: 发布时间:1970-01-01 08:00

CIFAR-10图像事物识别数据集

数据集下载地址:

链接: https://pan.baidu.com/s/1AlXpT7r0KUV_J2PtIFiasQ 提取码: pi8t


下载内容非图片格式,需通过python转换下,方法如下:

import numpy as np
from PIL import Image
import pickle
import os
 
CHANNEL = 3
WIDTH = 32
HEIGHT = 32
 
data = []
labels=[]
classification = ['airplane','automobile','bird','cat','deer','dog','frog','horse','ship','truck']
 
for i in range(5):
    with open(r"...\cifar-10-batches-py\data_batch_"+ str(i+1),mode='rb') as file:
        data_dict = pickle.load(file, encoding='bytes')
        data+= list(data_dict[b'data'])
        labels+= list(data_dict[b'labels'])
 
img =  np.reshape(data,[-1,CHANNEL, WIDTH, HEIGHT])
 
 
data_path = "data/images/"
if not os.path.exists(data_path):
    os.makedirs(data_path)
for i in range(img.shape[0]):
 
    r = img[i][0]
    g = img[i][1]
    b = img[i][2]
 
    ir = Image.fromarray(r)
    ig = Image.fromarray(g)
    ib = Image.fromarray(b)
    rgb = Image.merge("RGB", (ir, ig, ib))
 
    name = "img-" + str(i) +"-"+ classification[labels[i]]+ ".png"
    rgb.save(data_path + name, "PNG")

with open(r"...\cifar-10-batches-py\data_batch_"+ str(i+1),mode='rb') as file:这一句中第一个参数是文件的全路径。根据自己文件的存放位置该变这个参数。


标签:
Copyright © 2020 万物律动 旗下 AI算法狮 京ICP备20010037号-1
本站内容来源于网络开放内容的收集整理,并且仅供学习交流使用;
如有侵权,请联系删除相关内容;