CIFAR-10数据集可视化二进制版本

此代码针对的是CIFAR-10数据集的二进制格式

代码

import numpy as np
from scipy.misc import imsave


filename = '/tmp/cifar10_data/cifar-10-batches-bin/test_batch.bin'

bytestream = open(filename, "rb")
buf = bytestream.read(10000 * (1 + 32 * 32 * 3))
bytestream.close()

data = np.frombuffer(buf, dtype=np.uint8)
data = data.reshape(10000, 1 + 32*32*3)
labels_images = np.hsplit(data, [1])
labels = labels_images[0].reshape(10000)
images = labels_images[1].reshape(10000, 32, 32, 3)

img = np.reshape(images[1], (3, 32, 32)) #导出第一幅图
img = img.transpose(1, 2, 0)

imsave("cifar.jpg", img)

CIFAR-10数据集可视化二进制版本_第1张图片

你可能感兴趣的:(----Google,TensorFlow)