mnist lenet caffe 测试

# -*- coding: utf-8 -*-
import sys
import numpy as np
import struct
from PIL import Image
print "hell word"


filename = 't10k-images-idx3-ubyte'
binfile = open(filename,'rb')
buf = binfile.read()


index = 0
magic,numImages,numRows,numColumns = struct.unpack_from('>IIII',buf,index) # 指定类型读取数据,得到图片总数
index += struct.calcsize('>IIII')


for image in range(0,numImages):
im = struct.unpack_from('>784B',buf,index) #读一个图片
index +=struct.calcsize('>784B')

im = np.array(im,dtype = 'uint8')
im = im.reshape(28,28) #像素大小
im = Image.fromarray(im)
im.save('mnist_test/train_%s.bmp'%image,'bmp') #保存转换后的图片格式
posted @ 2018-11-30 13:15  水木清扬  阅读(162)  评论(0编辑  收藏  举报