TRAINING SET IMAGE FILE (train-images-idx3-ubyte):
[offset] [type]? ? ? ? ? [value]? ? ? ? ? [description]
0000? ? 32 bit integer? 0x00000803(2051) magic number
0004? ? 32 bit integer? 60000? ? ? ? ? ? number of images
0008? ? 32 bit integer? 28? ? ? ? ? ? ? number of rows
0012? ? 32 bit integer? 28? ? ? ? ? ? ? number of columns
//之后開始才是每張圖的每個像素的灰度數(shù)據(jù)
0016? ? unsigned byte? ??? ? ? ? ? ? ? pixel
0017? ? unsigned byte? ??? ? ? ? ? ? ? pixel
........
xxxx? ? unsigned byte? ??? ? ? ? ? ? ? pixel
首先該數(shù)據(jù)是以二進(jìn)制存儲的缅阳,我們讀取的時候要以’rb’方式讀仁臁;其次呵燕,真正的數(shù)據(jù)只有[value]這一項虏等,其他的[type]等只是來描述的适肠,并不真正在數(shù)據(jù)文件里面侯养。也就是說逛揩,在讀取真實數(shù)據(jù)之前,我們要讀取4個32 bit integer.由[offset]我們可以看出真正的pixel是從0016開始的惧笛,一個int 32位患整,所以在讀取pixel之前我們要讀取4個 32 bit integer各谚,也就是magic number, number of images, number of rows, number of columns. 當(dāng)然昌渤,在這里使用struct.unpack_from()會比較方便.
Training set images: train-images-idx3-ubyte.gz (9.9 MB, 解壓后 47 MB, 包含 60,000 個樣本)
Training set labels: train-labels-idx1-ubyte.gz (29 KB, 解壓后 60 KB, 包含 60,000 個標(biāo)簽)
Test set images: t10k-images-idx3-ubyte.gz (1.6 MB, 解壓后 7.8 MB, 包含 10,000 個樣本)
Test set labels: t10k-labels-idx1-ubyte.gz (5KB, 解壓后 10 KB, 包含 10,000 個標(biāo)簽)
最后得到images為二維矩陣,labels為一維矩陣了赵。