将CIFAR10数据显示出来

import os
import _pickle
import numpy as np
import matplotlib.pyplot as plt
filenames = [os.path.join('./data/cifar-10-batches-py','data_batch_%d'%i) for i in range(1,6)]
for index,filename in enumerate(filenames):
    with open(filename,'rb') as fp:
        data = _pickle.load(fp,encoding='bytes')#反序列化对象。将文件中的数据解析为一个Python对象
        value = np.asarray(data[b'data']).astype(np.float32)
        labels = np.asarray(data[b'labels']).astype(np.int32)
        for img in value:
            img = np.reshape(img,[32,32,3])
            plt.imshow(img)
            plt.pause(0.001)
        # mean = np.mean(value,axis=0)
        # img = np.reshape(mean,[32,32,3])

你可能感兴趣的:(python)