Python如何读入mnist二进制图像文件并显示-创新互联
小编这次要给大家分享的是Python如何读入mnist二进制图像文件并显示,文章内容丰富,感兴趣的小伙伴可以来了解一下,希望大家阅读完这篇文章之后能够有所收获。
图像文件是自己仿照mnist格式制作,每张图像大小为128*128
import struct import matplotlib.pyplot as plt import numpy as np #读入整个训练数据集图像 filename = 'train-images-idx3-ubyte' binfile = open(filename, 'rb') buf = binfile.read() #读取头四个32bit的interger index = 0 magic, numImages, numRows, numColumns = struct.unpack_from('>IIII', buf, index) index += struct.calcsize('>IIII') #读取一个图片,16384=128*128 im = struct.unpack_from('>16384B', buf, index) index += struct.calcsize('>16384B') im=np.array(im) im=im.reshape(128,128) fig = plt.figure() plotwindow = fig.add_subplot(111) plt.imshow(im, cmap = 'gray') plt.show()
本文名称:Python如何读入mnist二进制图像文件并显示-创新互联
当前网址:http://tyjierui.cn/article/ceghgj.html