zl程序教程

您现在的位置是:首页 >  大数据

当前栏目

Mnist数据集解析

数据 解析 mnist
2023-09-11 14:15:46 时间

Mnist数据集是手写数字图像集,MNIST是机器学习领域最有名的数据集之一,被应用于从简单的实验到发表研究论文等各种场合。Mnist数据集是由0到9的数字图像构成,训练图像有6万张,测试图像有1万张,这些图像可以用于学习和推理。

MNIST 数据集来自美国国家标准与技术研究所, National Institute of Standards and Technology (NIST). 训练集 (training set) 由来自 250 个不同人手写的数字构成, 其中 50% 是高中学生, 50% 来自人口普查局 (the Census Bureau) 的工作人员. 测试集(test set) 也是同样比例的手写数字数据.

MNIST数据集的一般使用方法是,先用训练图像进行学习,再用学习到的模型对测试图像进行正确的分类。

下载MNIST数据集,有两种方式,可以直接去MNIST的官网下载,地址:MNIST handwritten digit database, Yann LeCun, Corinna Cortes and Chris Burges

如下图:

或者运行下面的Python程序,可以完成对MNIST数据的下载:

# coding: utf-8
try:
    import urllib.request
except ImportError:
    raise ImportError('You should use Python 3.x')
import os.path
import gzip
import pickle
import os
import numpy as np
from PIL import Image

url_base = 'http://yann.lecun.com/exdb/mnist/'
key_file = {
    'train_img':'train-images-idx3-ubyte.gz',
    'train_label':'train-labels-idx1-ubyte.gz',
    'test_img':'t10k-images-idx3-ubyte.gz',
    'test_label':'t10k-labels-idx1-ubyte.gz'
}

dataset_dir = os.path.dirname(os.path.abspath(__file__))
save_file = dataset_dir + "/mnist.pkl"

train_num = 60000
test_num = 10000
img_dim = (1, 28, 28)
img_size = 784


def _download(file_name):
    file_path = dataset_dir + "/" + file_name
    
    if os.path.exists(file_path):
        return

    print("Downloading " + file_name + " ... ")
    urllib.request.urlretrieve(url_base + file_name, file_path)
    print("Done")
    
def download_mnist():
    for v in key_file.values():
       _download(v)
        
def _load_label(file_name):
    file_path = dataset_dir + "/" + file_name
    
    print("Converting " + file_name + " to NumPy Array ...")
    with gzip.open(file_path, 'rb') as f:
            labels = np.frombuffer(f.read(), np.uint8, offset=8)
    print("Done")
    
    return labels

def _load_img(file_name):
    file_path = dataset_dir + "/" + file_name
    
    print("Converting " + file_name + " to NumPy Array ...")    
    with gzip.open(file_path, 'rb') as f:
            data = np.frombuffer(f.read(), np.uint8, offset=16)
    data = data.reshape(-1, img_size)
    print("Done")
    
    return data
    
def _convert_numpy():
    dataset = {}
    dataset['train_img'] =  _load_img(key_file['train_img'])
    dataset['train_label'] = _load_label(key_file['train_label'])    
    dataset['test_img'] = _load_img(key_file['test_img'])
    dataset['test_label'] = _load_label(key_file['test_label'])
    
    return dataset

def init_mnist():
    download_mnist()
    dataset = _convert_numpy()
    print("Creating pickle file ...")
    with open(save_file, 'wb') as f:
        pickle.dump(dataset, f, -1)
    print("Done!")

def _change_one_hot_label(X):
    T = np.zeros((X.size, 10))
    for idx, row in enumerate(T):
        row[X[idx]] = 1
        
    return T
    

def load_mnist(normalize=True, flatten=True, one_hot_label=False):
    """读入MNIST数据集
    
    Parameters
    ----------
    normalize : 将图像的像素值正规化为0.0~1.0
    one_hot_label : 
        one_hot_label为True的情况下,标签作为one-hot数组返回
        one-hot数组是指[0,0,1,0,0,0,0,0,0,0]这样的数组
    flatten : 是否将图像展开为一维数组
    
    Returns
    -------
    (训练图像, 训练标签), (测试图像, 测试标签)
    """
    if not os.path.exists(save_file):
        init_mnist()
        
    with open(save_file, 'rb') as f:
        dataset = pickle.load(f)
    
    if normalize:
        for key in ('train_img', 'test_img'):
            dataset[key] = dataset[key].astype(np.float32)
            dataset[key] /= 255.0
            
    if one_hot_label:
        dataset['train_label'] = _change_one_hot_label(dataset['train_label'])
        dataset['test_label'] = _change_one_hot_label(dataset['test_label'])
    
    if not flatten:
         for key in ('train_img', 'test_img'):
            dataset[key] = dataset[key].reshape(-1, 1, 28, 28)

    return (dataset['train_img'], dataset['train_label']), (dataset['test_img'], dataset['test_label']) 


if __name__ == '__main__':
    init_mnist()

def img_show(img):
    pil_img = Image.fromarray(np.uint8(img))
    pil_img.show()
 
(x_train, t_train), (x_test, t_test) = load_mnist(flatten=True, normalize=False)
 
img = x_train[0]
label = t_train[0]
print(label)  # 5 
 
print(img.shape)  # (784,)
img = img.reshape(28, 28)  # 把图像的形状变为原来的尺寸
print(img.shape)  # (28, 28)
 
img_show(img)

运行后:

下载的MNIST包含如下文件

每个文件的作用分别解释如下:

  1. t10k-images-idx3-ubyte.gz,大小1.6M,包含 10,000 个样本.
  2. t10k-labels-idx1-ubyte.gz,大小4.5K,包含 10,000 个标签.
  3. train-images-idx3-ubyte.gz,大小9.5M,包含 60,000 个样本.
  4. train-labels-idx1-ubyte.gz,大小29K,包含 60,000 个标签.

解压之后是纯数据文件,如下图:

总用量 53M
-rw-rw-r-- 1 caozilong caozilong 7.5M 8月  23 22:20 t10k-images-idx3-ubyte
-rw-rw-r-- 1 caozilong caozilong 9.8K 8月  23 22:20 t10k-labels-idx1-ubyte
-rw-rw-r-- 1 caozilong caozilong  45M 8月  23 22:20 train-images-idx3-ubyte
-rw-rw-r-- 1 caozilong caozilong  59K 8月  23 22:20 train-labels-idx1-ubyte

下面是官网的介绍:

上面的代码执行后,输出是这个样子:

内容格式:

首先看一下标签格式,官网有关于格式的介绍:

首先看一下测试集标签:

xxd -g 4 t10k-labels-idx1-ubyte |more

根据格式说明, 0x00000801(2049) 是magic number (MSB first),0x00002710=10000=10k.后面每个字节表示一个数字标签,所以按照道理,文件的大小应该是(4+4+10000)字节=10008字节=0x2718.

我们dump文件内容,实际的大小确实是0x2718.

caozilong@caozilong-Vostro-3268:~/ml/dataset/mnist$ xxd -g 4 t10k-labels-idx1-ubyte |more
00000000: 00000801 00002710 07020100 04010409  ......'.........
00000010: 05090006 09000105 09070304 09060605  ................
00000020: 04000704 00010301 03040702 07010201  ................
00000030: 01070402 03050102 04040603 05050600  ................
00000040: 04010905 07080903 07040604 03000700  ................
00000050: 02090107 03020907 07060207 08040703  ................
00000060: 06010306 09030104 01070609 06000504  ................
00000070: 09090201 09040807 03090704 04040902  ................
00000080: 05040706 07090005 08050606 05070801  ................
00000090: 00010604 06070301 07010802 00020909  ................
000000a0: 05050105 06000304 04060504 06050405  ................
000000b0: 01040407 02030207 01080108 01080500  ................
000000c0: 08090205 00010101 00090003 01060402  ................
000000d0: 03060101 01030905 02090405 09030900  ................
000000e0: 03060505 07020207 01020804 01070303  ................
000000f0: 08080709 02020401 05090807 02030004  ................
00000100: 04020401 09050707 02080206 08050707  ................
00000110: 09010801 08000300 01090904 01080201  ................
00000120: 02090705 09020604 01050802 09020004  ................
00000130: 00000208 04070102 04000207 04030300  ................
00000140: 00030109 06050205 09020903 00040200  ................
00000150: 07010102 01050303 09070806 05060103  ................
00000160: 08010005 01030105 05060108 05010709  ................
00000170: 04060202 05000605 06030702 00080805  ................
00000180: 04010104 00030307 06010602 01090208  ................
00000190: 06010905 02050404 02080308 02040500  ................
000001a0: 03010707 05070907 01090201 04020902  ................
000001b0: 00040901 04080108 04050908 08030706  ................
000001c0: 00000300 02060604 09030303 02030901  ................
000001d0: 02060800 05060606 03080802 07050809  ................
000001e0: 06010804 01020509 01090705 04000809  ................
000001f0: 09010005 02030708 09040006 03090502  ................
00000200: 01030103 06050704 02020603 02060504  ................
00000210: 08090701 03000308 03010903 04040604  ................
00000220: 02010802 05040808 04000002 03020707  ................
00000230: 00080704 04070906 09000908 00040600  ................
00000240: 06030504 08030309 03030307 08000802  ................
00000250: 01070006 05040308 00090603 08000909  ................
00000260: 06080608 05070806 00020400 02020301  ................
00000270: 09070501 00080406 02060709 03020908  ................
00000280: 02020902 07030509 01080002 00050201  ................
00000290: 03070607 01020508 00030702 04000901  ................
000002a0: 08060707 04030409 01090501 07030907  ................
000002b0: 06090103 07080303 06070208 05080501  ................
000002c0: 01040403 01000707 00070904 04080505  ................
000002d0: 04000802 01000804 05000400 06010703  ................
000002e0: 02060702 06090301 04060205 04020006  ................
000002f0: 02010703 04010005 04030101 07040909  ................
00000300: 04080400 02040501 01060407 01090402  ................
00000310: 04010505 03080301 04050608 09040105  ................
00000320: 03080003 02050102 08030404 00080803  ................
00000330: 03010703 05090603 02060103 06000702  ................
00000340: 01070104 02040201 07090601 01020408  ................
00000350: 01070704 08000703 01030100 07070003  ................
00000360: 05050207 06060902 08030502 02050600  ................
00000370: 08020902 08080808 07040903 00060603  ................
00000380: 02010302 02090300 00050708 01040406  ................
00000390: 00020901 04070407 03090808 04070102  ................
000003a0: 01020203 02030203 09010704 00030505  ................
000003b0: 08060302 06070606 03020708 01010705  ................
000003c0: 06040905 01030304 07080901 01060901  ................
000003d0: 04040504 00060202 03010501 02000308  ................
000003e0: 01020607 01060203 09000102 02000809  ................
000003f0: 09000205 01090708 01000401 07090604  ................
00000400: 02060801 03070504 04010801 03080102  ................
00000410: 05080006 02010107 01050304 06090500  ................
00000420: 09020204 08020107 02040904 04000309  ................
00000430: 02020303 08030507 03050801 02040406  ................
00000440: 04090501 00060905 09050907 03080003  ................
00000450: 07010306 07080509 07090609 06030704  ................
00000460: 04050305 04070807 08000706 08080703  ................
00000470: 03010905 02070305 01010201 04070407  ................
00000480: 05040504 00080306 09060002 07040404  ................
00000490: 04060604 07090304 05050807 03070207  ................
000004a0: 00020401 01060609 02080702 00010500  ................
000004b0: 09010700 06000806 08010800 03030702  ................
000004c0: 03060201 06010103 07090008 00050400  ................
000004d0: 02080702 09080400 09050805 01020103  ................
000004e0: 01070405 07020009 08080602 05040109  ................
000004f0: 02010508 07000204 04030608 08020400  ................
00000500: 05000404 07090304 01050907 03050808  ................
00000510: 00050303 06060001 06000305 04040102  ................
00000520: 09010406 09090309 08040403 01030108  ................
00000530: 08070904 08080709 07010405 06000502  ................
00000540: 02020105 05020409 06020707 02020101  ................
00000550: 02080307 02040107 01070607 08020703  ................
00000560: 01070508 02060202 05060500 09020403  ................
00000570: 03090706 06080004 01050802 09010800  ................
00000580: 06070201 00050502 00020200 02040908  ................
00000590: 00090904 06050409 01080304 09090102  ................
000005a0: 02080109 06040009 04080308 06000205  ................
000005b0: 01090602 09040009 06000602 05040203  ................
000005c0: 08040505 00030805 03050806 05070603  ................
000005d0: 03090601 01020900 04030306 09050703  ................
000005e0: 07070708 07090803 00070207 09040504  ................
000005f0: 09030201 04000203 07050708 08050001  ................
00000600: 01040803 09000000 06060203 07080407  ................
00000610: 07090204 01040502 04090901 08040009  ................
00000620: 08040807 07000708 08060004 08080204  ................
00000630: 07060606 04070108 08020306 03000003  ................
00000640: 07060907 09090504 03030601 02030703  ................
00000650: 03020003 03080403 06030500 02000900  ................
00000660: 07040609 03050109 06010405 04050005  ................
00000670: 09050201 02090109 09040008 04050209  ................
00000680: 02010201 07030608 08040901 09080507  ................
00000690: 05010108 06050204 04030203 05060808  ................
000006a0: 06020301 00050809 02090607 00040807  ................
000006b0: 01070401 00090702 00000901 07080708  ................
000006c0: 04070200 04060003 01010303 09060704  ................
000006d0: 01050300 08070309 06090305 00020704  ................
000006e0: 05010705 08000808 01050003 00030104  ................
000006f0: 00030702 07010800 07000403 01090807  ................
00000700: 07010409 09030201 07090002 00030307  ................
00000710: 06090203 03070700 00070502 09080704  ................
00000720: 04020606 01090608 02090008 03010106  ................
00000730: 03050101 01030102 03000200 01030505  ................
00000740: 07040809 06090608 03060608 05010402  ................
00000750: 04040501 01090002 04090507 01080805  ................
00000760: 06090807 01010607 06030202 00080902  ................
00000770: 05010008 01090507 09060900 06010505  ................
00000780: 08030802 06050007 04060103 04070302  ................
00000790: 03040205 02070107 02060401 05070806  ................
000007a0: 00010802 05070706 09030508 04020400  ................
000007b0: 08080304 09020705 08060506 00080607  ................
000007c0: 03060409 04060603 02040100 01040602  ................
000007d0: 09010100 06030905 06050605 08040604  ................
000007e0: 03090103 04010901 07010109 03050400  ................
000007f0: 07030601 07050503 03000105 07050806  ................
00000800: 05010004 02030406 07090801 08040902  ................
00000810: 08060207 00000607 05080600 09030701  ................
00000820: 03050403 03050506 03000203 04020300  ................
00000830: 09090407 02080407 00060208 05020805  ................
00000840: 07030008 02030208 02050507 06040608  ................
00000850: 04080207 04050200 03090406 07020506  ................
00000860: 01010203 06070807 06040809 04080603  ................
00000870: 08030100 06020205 06090508 01040107  ................
00000880: 08040601 08040301 02080008 05090104  ................
00000890: 02000207 00090002 05070607 09040206  ................
000008a0: 02040408 00040405 08000608 09080506  ................
000008b0: 09000408 07010304 05080009 01030306  ................
000008c0: 09080701 00050701 07050207 09010805  ................
000008d0: 02040904 07020203 04090109 02010709  ................
000008e0: 04040106 07020708 08010907 01010705  ................
000008f0: 03030501 03070601 03080705 09090000  ................
00000900: 02080802 03070103 00030404 03080902  ................
00000910: 03090701 01070004 09060509 01070002  ................
00000920: 00000406 07000701 04060405 04090901  ................
00000930: 07090503 03080203 06020201 01010101  ................
00000940: 06090804 03070106 04050004 07040204  ................
00000950: 00070001 09080806 00000409 06080202  ................
00000960: 03080408 02020107 05040400 04030907  ................
00000970: 03010001 02050902 01000108 09010608  ................
00000980: 03080903 06020803 02020100 04020902  ................
00000990: 04030709 01050204 09000308 05030600  ................
000009a0: 09040602 05000207 04060608 06060806  ................
000009b0: 09010702 05090900 07020706 07000605  ................
000009c0: 02040702 00090902 02090404 02030302  ................
000009d0: 01070007 06040103 08070405 09020501  ................
000009e0: 08070307 01050500 09010400 06030306  ................
000009f0: 00040907 05010608 09050507 09030803  ................
00000a00: 08010503 05000505 03080607 07070307  ................
00000a10: 00050900 02050503 01070708 06050903  ................
00000a20: 08090503 07090107 00000307 02050801  ................
00000a30: 08060209 05070507 08060205 01040804  ................
00000a40: 05080300 06020703 03020100 07030400  ................
00000a50: 03090302 08090003 08000706 05040703  ................
00000a60: 09000806 02050601 00000404 00010203  ................
00000a70: 02070708 05020507 06090104 01060402  ................
00000a80: 04030504 03090500 01050308 09010907  ................
00000a90: 09050502 07040600 01010100 04040706  ................
00000aa0: 03000004 03000601 09060103 08010205  ................
00000ab0: 06020703 06000109 07060608 09020905  ................
00000ac0: 08030100 00070606 02010609 03010806  ................
00000ad0: 09000600 00000603 05090304 05050805  ................
00000ae0: 03000400 02090608 02030102 01010506  ................
00000af0: 09080006 06050503 08060201 04050403  ................
00000b00: 07080500 09030501 01000404 07000107  ................
00000b10: 00010601 04050606 05070804 04070205  ................
00000b20: 03070007 07090604 02080507 08030905  ................
00000b30: 08090908 06020809 02030601 01080903  ................
00000b40: 04000709 06040104 01030409 03010407  ................
00000b50: 07040702 09030008 08080400 04040105  ................
00000b60: 02080304 09050208 01050307 09040205  ................
00000b70: 06030509 03050903 01090503 00060908  ................
00000b80: 04000409 02090001 00030106 05080105  ................
00000b90: 03030003 05050902 08070004 09010907  ................
00000ba0: 07050502 00090108 06020309 06020109  ................
00000bb0: 01030505 00030803 03070606 00010400  ................
00000bc0: 06090801 02090905 09070307 08000103  ................
00000bd0: 00040601 00020508 04040101 05040606  ................
00000be0: 00060902 06020701 07090400 00030802  ................
00000bf0: 02030106 00050707 09020607 09070806  ................
00000c00: 08080406 08040102 08010309 04000307  ................
00000c10: 03020303 07030400 06020008 01050305  ................
00000c20: 04010701 05070507 03020207 03070307  ................
00000c30: 08050405 02050605 03060704 01070105  ................
00000c40: 02030603 01040206 07040308 00060201  ................
00000c50: 06050309 01090302 01080404 06050806  ................
00000c60: 09070708 06090703 09040005 04060401  ................
00000c70: 02030000 02060605 07000806 04070900  ................
00000c80: 07030402 01080805 09020701 08080802  ................
00000c90: 07060001 02070100 08030600 05030602  ................
00000ca0: 08070001 04020101 04040404 07010602  ................
00000cb0: 09090000 01080804 03040200 06010601  ................
00000cc0: 02020201 02030708 01000002 01060600  ................
00000cd0: 01060205 01070408 02010403 08030909  ................
00000ce0: 04080304 07020705 07000403 03020607  ................
00000cf0: 06000006 07070005 05080100 07000208  ................
00000d00: 01050008 08000302 07070206 04070505  ................
00000d10: 05020902 08040608 06050000 08070601  ................
00000d20: 07010102 07040000 07070603 08060402  ................
00000d30: 00090400 05070802 07040701 01030606  ................
00000d40: 02090109 04080306 09050906 02040607  ................
00000d50: 07000606 09040803 05030409 00000502  ................
00000d60: 05000701 01010607 06070906 06040104  ................
00000d70: 03010102 02040100 08070603 04000006  ................
00000d80: 03030007 01070101 03010009 09070504  ................
00000d90: 01040809 05030501 09080203 03090900  ................
00000da0: 01000209 03090303 06020409 08030704  ................
00000db0: 00040708 04090809 09070509 02080202  ................
00000dc0: 00020203 08040608 06080204 06070903  ................
00000dd0: 03090403 01040407 00050906 00040404  ................
00000de0: 04060102 03030604 05090608 05060508  ................
00000df0: 06040108 06050208 04050504 07070007  ................
00000e00: 08020203 07000108 00070109 08070505  ................
00000e10: 09010705 04090102 02010606 07010104  ................
00000e20: 00070402 04000604 07060905 03040605  ................
00000e30: 00010808 02080305 07080008 05070101  ................
00000e40: 00010307 08050007 01010001 01040502  ................
00000e50: 07060203 00020805 09060907 02010306  ................
00000e60: 04010802 04000501 00020206 04040309  ................
00000e70: 06010605 07090200 02060001 04030502  ................
00000e80: 08080008 08090009 06070603 09030407  ................
00000e90: 07070409 00060408 04020702 08010000  ................
00000ea0: 07080303 03010307 06010301 06060507  ................
00000eb0: 04070509 05080409 09010605 00010307  ................
00000ec0: 00030408 02020002 05010501 04080809  ................
00000ed0: 01020103 05010009 04040803 02050907  ................
00000ee0: 06060200 00000508 07010502 03080501  ................
00000ef0: 08020004 09090602 03030506 04080009  ................
00000f00: 02080306 07050702 09040901 02080600  ................
00000f10: 07000901 01060705 09090109 05090205  ................
00000f20: 00040100 08090008 09080904 02050709  ................
00000f30: 08090800 09090608 09090509 08050100  ................
00000f40: 03030502 01060500 02080105 06020300  ................
00000f50: 02020604 03050501 07020106 09010909  ................
00000f60: 05050106 02020806 07010406 00040003  ................
00000f70: 03020203 06080908 05030805 04050200  ................
00000f80: 05060302 08030909 05070904 06070103  ................
00000f90: 07030606 00090001 09090208 08000106  ................
00000fa0: 09070503 04070409 09040306 03010107  ................
00000fb0: 06090108 04010109 09040306 08010600  ................
00000fc0: 04010307 07040905 01000001 01060201  ................
00000fd0: 09080400 03060409 00070106 05070502  ................
00000fe0: 05010805 04070006 07000205 08010004  ................
00000ff0: 05070108 05010900 00060007 03010803  ................
00001000: 09070000 08090509 08030207 02090702  ................
00001010: 01010307 05030109 08020202 08080507  ................
00001020: 03080908 08060802 03090705 06020902  ................
00001030: 08080106 08080709 01080001 07020007  ................
00001040: 05010900 02000908 06020309 03080002  ................
00001050: 01010101 04020907 02050101 02010909  ................
00001060: 09010002 00020101 04060401 05040907  ................
00001070: 07010506 02020208 00060906 01090707  ................
00001080: 01040805 03040304 09070500 07040808  ................
00001090: 01050309 05090706 09000306 03090802  ................
000010a0: 02010208 06080505 03090409 02050105  ................
000010b0: 01040401 04040305 09010202 03030002  ................
000010c0: 09000009 09060009 03020804 01090907  ................
000010d0: 02070909 05090501 01080305 01090503  ................
000010e0: 05040905 09030109 00090705 04090200  ................
000010f0: 01000501 04090303 06010502 05020200  ................
00001100: 09020606 00010200 03000205 05070905  ................
00001110: 05000809 05000302 05090008 08040508  ................
00001120: 08040504 08050409 02020102 06080807  ................
00001130: 00030606 04030808 07020200 00090309  ................
00001140: 09010908 06060402 06090208 05040507  ................
00001150: 09090902 01080304 00070803 09030406  ................
00001160: 05060203 09020600 00060102 08070908  ................
00001170: 02000407 07050005 06040607 04030007  ................
00001180: 05000704 02000809 09040204 06070807  ................
00001190: 06090401 03070300 08080706 09030902  ................
000011a0: 02090201 08030209 06080400 01020804  ................
000011b0: 05020708 01010300 03050700 03010903  ................
000011c0: 06030107 07030008 04080206 05020907  ................
000011d0: 03090009 09060402 09070201 01060704  ................
000011e0: 07050906 08020104 04050706 01030205  ................
000011f0: 09090306 01010406 09070201 05010406  ................
00001200: 03080101 00030106 08040900 07030002  ................
00001210: 09000606 06030607 07020806 00080300  ................
00001220: 02090803 02050308 08000001 09050103  ................
00001230: 09060001 04010701 02030709 07040909  ................
00001240: 03090208 02070108 00090100 01070709  ................
00001250: 06090909 02010601 03050701 09070604  ................
00001260: 05070606 09090603 06020908 01020205  ................
00001270: 05020307 02010001 00040502 08020803  ................
00001280: 05010708 01010209 07080400 03000708  ................
00001290: 08040707 08050804 09080103 08000301  ................
000012a0: 07090505 01060507 04090305 04070102  ................
000012b0: 00080106 00070304 07030906 00080604  ................
000012c0: 08070709 03080609 07020304 00020108  ................
000012d0: 03050507 02040607 02080300 08070809  ................
000012e0: 00080404 05080506 06030009 03070608  ................
000012f0: 09030409 05080901 02080806 08010307  ................
00001300: 09000101 04070008 01070405 07010201  ................
00001310: 01030906 02010208 00070606 09030700  ................
00001320: 05020800 05040308 04060602 07090501  ................
00001330: 03020403 06010904 04070605 04010909  ................
00001340: 02070800 01030601 03040101 01050600  ................
00001350: 07000702 03020502 02090409 08010201  ................
00001360: 06010207 08000000 08020209 02020709  ................
00001370: 09020705 01030409 04010805 06020803  ................
00001380: 01020804 09090307 00070702 03020400  ................
00001390: 03090908 04010006 00090608 06010109  ................
000013a0: 08090203 05050904 02010904 03090600  ................
000013b0: 04000600 01020304 07080900 01020304  ................
000013c0: 07080900 01020304 05060708 09080304  ................
000013d0: 07080603 04000907 01090308 04070300  ................
000013e0: 09010405 04060200 06020101 01010702  ................
000013f0: 04070502 09040508 04020907 00000705  ................
00001400: 01010706 06060802 02070704 00020402  ................
00001410: 01080906 01000509 06090800 03000803  ................
00001420: 09060300 01020304 05060700 01020304  ................
00001430: 05060708 09000102 03040506 07080504  ................
00001440: 08070407 07030908 08030105 08020704  ................
00001450: 02010504 05050806 04040401 08070505  ................
00001460: 01080901 03060303 02020609 09060505  ................
00001470: 03030801 06050608 01090706 08030704  ................
00001480: 07000900 00030709 03000200 01000100  ................
00001490: 04000100 04070906 02060202 09090001  ................
000014a0: 02030405 06070809 00010203 04050607  ................
000014b0: 08090001 02030405 06070809 08000506  ................
000014c0: 06000800 02030709 04070109 01070104  ................
000014d0: 00000401 07050701 03030301 06090704  ................
000014e0: 03000205 02060008 09040305 04080105  ................
000014f0: 09000604 03060303 08010407 05070202  ................
00001500: 00000107 07090509 08090608 08020306  ................
00001510: 01020908 09050206 02040804 06050001  ................
00001520: 05060708 09000102 03040506 07080900  ................
00001530: 01020304 05060708 09070402 00090001  ................
00001540: 05080800 02070804 04060100 04050309  ................
00001550: 04020005 00010302 09010600 01010800  ................
00001560: 04070706 03060007 03050402 04010803  ................
00001570: 05060700 06070102 05080109 03080208  ................
00001580: 07060701 04060209 03000102 03040506  ................
00001590: 07000102 03040500 01020809 01040009  ................
000015a0: 05000800 07070101 02090306 07020308  ................
000015b0: 01020908 08070107 01010003 04020604  ................
000015c0: 07040207 04090100 06080505 05030509  ................
000015d0: 07040805 09060903 00030809 01080106  ................
000015e0: 00000102 03040506 07080900 01020304  ................
000015f0: 05060708 09000102 03040506 07080903  ................
00001600: 05030209 03020104 05050203 02010309  ................
00001610: 07020102 08090108 08070801 00000707  ................
00001620: 08070500 06010507 04060102 05000709  ................
00001630: 09000308 04040801 08060509 00000003  ................
00001640: 07010604 02060600 04050401 03080603  ................
00001650: 09090509 03070805 06040706 02020009  ................
00001660: 04000102 03040506 07080900 01020305  ................
00001670: 06000102 03040506 08070103 02080007  ................
00001680: 05090906 00090401 03020102 03080302  ................
00001690: 06050608 02070408 01080005 03090401  ................
000016a0: 09020109 06070900 04060107 03080702  ................
000016b0: 09060508 03090005 07010601 00090303  ................
000016c0: 04040006 02050402 03040600 00020001  ................
000016d0: 04050607 08090001 02030405 06070800  ................
000016e0: 01020304 05060708 09080701 03070502  ................
000016f0: 08000705 09090009 01010508 08060302  ................
00001700: 01080302 06050607 04010005 03010902  ................
00001710: 01090600 04060107 03080702 09060508  ................
00001720: 03050701 06010009 06020504 02030404  ................
00001730: 06000002 00010203 04050607 08090001  ................
00001740: 02030405 06070809 00010203 04050607  ................
00001750: 08090806 05000608 09040109 05030004  ................
00001760: 08090104 00050502 01050400 07060001  ................
00001770: 07000608 09050107 09080600 08010707  ................
00001780: 01030203 01040200 00070804 06040903  ................
00001790: 08040702 05060306 09060302 02040609  ................
000017a0: 00020505 01030309 07080702 02050709  ................
000017b0: 08020103 01030001 02030405 06070809  ................
000017c0: 00010203 04050607 08090001 02030405  ................
000017d0: 06070809 01020605 03000700 04010403  ................
000017e0: 06070203 01020102 09060001 03000207  ................
000017f0: 05070602 09010900 06000600 02000601  ................
00001800: 05080403 00010504 04080507 05070803  ................
00001810: 04080805 02090701 03080100 07050906  ................
00001820: 09040707 09090304 04030806 02000102  ................
00001830: 03040506 07080900 01020304 05060708  ................
00001840: 09000102 03040506 07080900 08030905  ................
00001850: 05020608 04090107 01020305 09060901  ................
00001860: 01010209 05060801 02000707 05080209  ................
00001870: 08090004 06070103 04050600 03060807  ................
00001880: 00040207 04070504 03040208 01050102  ................
00001890: 00020506 04030000 00030305 07000604  ................
000018a0: 08080603 04060909 08020707 01000102  ................
000018b0: 03040506 07080900 01020304 05060708  ................
000018c0: 00010203 04050607 08020107 02050008  ................
000018d0: 00020708 08030600 02070606 01020808  ................
000018e0: 07070407 07030704 05040303 08040101  ................
000018f0: 09070403 07030300 02050506 06030502  ................
00001900: 05090908 04010006 00090608 08050601  ................
00001910: 01090809 02030505 09040201 09030902  ................
00001920: 00060004 00000102 03040708 09000102  ................
00001930: 03070809 00010203 04070809 07030003  ................
00001940: 01080706 04000206 08030208 01020007  ................
00001950: 01000404 05080006 02030105 01080509  ................
00001960: 04000705 08080308 09020602 05030107  ................
00001970: 03090109 09060003 09020801 04030502  ................
00001980: 09020508 09050001 02040506 00010203  ................
00001990: 04050607 01020304 05010004 05060603  ................
000019a0: 04040208 01000604 09070203 03090200  ................
000019b0: 09030309 01050203 07070804 00020400  ................
000019c0: 02040708 00070006 09030208 06000507  ................
000019d0: 05010008 01060702 09070905 08060206  ................
000019e0: 02080107 05000101 03080409 01080608  ................
000019f0: 09000102 03040506 07080900 01020304  ................
00001a00: 07080900 01070809 09080908 04010707  ................
00001a10: 03030706 06060109 00010706 03020107  ................
00001a20: 01030901 07060804 01040306 09060104  ................
00001a30: 04070204 04000102 03040506 07080900  ................
00001a40: 01020304 05060900 01020304 07080103  ................
00001a50: 05010707 02010408 03040403 09070401  ................
00001a60: 02030509 01060001 00000208 07010104  ................
00001a70: 00040703 06080003 07040006 09020605  ................
00001a80: 08060900 04000601 09020009 05010307  ................
00001a90: 06090300 02020001 02030405 06070809  ................
00001aa0: 00010203 04050607 08090001 02030405  ................
00001ab0: 06070809 02010702 05000800 02070808  ................
00001ac0: 03000600 02070606 01020808 07070407  ................
00001ad0: 07030704 05040303 08040504 01010907  ................
00001ae0: 04030703 03000205 05060301 05020509  ................
00001af0: 09080401 00060009 06080805 06010109  ................
00001b00: 08090203 05050904 02010904 09010309  ................
00001b10: 02000600 04000600 01020304 05060708  ................
00001b20: 09000102 03040506 07080900 01020304  ................
00001b30: 05060708 09030800 07010007 05050609  ................
00001b40: 00010000 08030403 01050000 09050304  ................
00001b50: 09030706 09020405 07020604 09040904  ................
00001b60: 01020205 08010302 09040308 02020102  ................
00001b70: 08060501 06070201 03090308 07050700  ................
00001b80: 07040808 05000606 03070609 09040804  ................
00001b90: 01000606 00010203 04050607 08090001  ................
00001ba0: 02030405 06070809 00010203 04050607  ................
00001bb0: 08090704 00040001 07090501 04020809  ................
00001bc0: 04030708 02040403 03060909 05080607  ................
00001bd0: 00060802 06030903 02080601 07040808  ................
00001be0: 09000303 09000502 09040100 03070508  ................
00001bf0: 07070802 09070102 06040205 02030606  ................
00001c00: 05000002 08010601 00040301 06010900  ................
00001c10: 01040506 07080901 02030405 06070001  ................
00001c20: 02030405 06070809 08040000 07020403  ................
00001c30: 08060603 02060303 00010407 08000301  ................
00001c40: 09000109 01020700 01030802 09020706  ................
00001c50: 05050909 08020901 03020304 03010900  ................
00001c60: 09030608 07000100 05080207 07000102  ................
00001c70: 03040506 07080900 01020304 05060708  ................
00001c80: 09000102 03040506 07080901 07040801  ................
00001c90: 05060507 02080603 03080605 04000901  ................
00001ca0: 07020901 05010302 02030006 04030706  ................
00001cb0: 09000408 01040006 01020609 02020305  ................
00001cc0: 05010007 07090602 09040700 02030400  ................
00001cd0: 00080808 05010307 04090808 09000908  ................
00001ce0: 09000206 05060704 07050401 03050301  ................
00001cf0: 02030405 06010203 04060001 02040506  ................
00001d00: 07080107 02040104 01040906 08040503  ................
00001d10: 07080403 03050607 00060106 08070001  ................
00001d20: 05000805 00010508 04020309 07060901  ................
00001d30: 09000607 01020309 02040505 03070503  ................
00001d40: 01080202 03000209 04090700 02070409  ................
00001d50: 09020509 08030806 07000001 02030405  ................
00001d60: 06070809 00010203 04050607 08090001  ................
00001d70: 02030405 06070809 00000702 06050503  ................
00001d80: 07080606 06060403 08080300 01090005  ................
00001d90: 04010901 02070001 03080209 02070402  ................
00001da0: 06050509 09010105 07060802 09040301  ................
00001db0: 09000903 06080700 01000508 02070700  ................
00001dc0: 01020304 05060708 09000102 03040508  ................
00001dd0: 09000102 03040506 07080902 01020103  ................
00001de0: 09090805 03070007 07050709 09040700  ................
00001df0: 03040105 08010408 04010806 06040600  ................
00001e00: 05050303 05070205 09060902 06020102  ................
00001e10: 00080308 03000807 04090500 09070000  ................
00001e20: 04060009 01060207 06080305 02010803  ................
00001e30: 08060100 02010400 01020304 05060708  ................
00001e40: 09000102 03040506 07080900 01020304  ................
00001e50: 05060708 09070604 07060203 04080708  ................
00001e60: 06090803 02020804 08050605 00020001  ................
00001e70: 01020906 08020100 06050209 07050309  ................
00001e80: 03070108 03080109 05050001 01090802  ................
00001e90: 06000405 00030108 06070509 09030003  ................
00001ea0: 01040400 04090001 02030506 07080001  ................
00001eb0: 02030506 07080900 01020305 06070809  ................
00001ec0: 09070009 00010508 08000903 02070804  ................
00001ed0: 06010004 09040200 05000106 09030209  ................
00001ee0: 01060001 01080707 06030600 07020401  ................
00001ef0: 07000607 01020508 01080208 07060807  ................
00001f00: 01060209 03000102 03040506 07080900  ................
00001f10: 01020304 05060708 09000102 03040506  ................
00001f20: 07080908 09050700 03010608 04010506  ................
00001f30: 04020708 01030403 04070200 05000109  ................
00001f40: 02030203 05050708 04090907 01010900  ................
00001f50: 07080304 08060308 00090602 01000100  ................
00001f60: 06020308 09000702 03040505 02080504  ................
00001f70: 06060607 09010802 01050304 07090400  ................
00001f80: 00000102 03040506 07080900 01020304  ................
00001f90: 05060708 09000102 03040506 09000103  ................
00001fa0: 01050102 04090204 06080001 01090206  ................
00001fb0: 06080704 02090700 02010003 06000102  ................
00001fc0: 03040506 07080900 01020304 05060708  ................
00001fd0: 09000102 03040506 07080908 06050907  ................
00001fe0: 00020304 03080501 05020300 01020103  ................
00001ff0: 02060503 00070207 04060400 05090908  ................
00002000: 09050301 07040706 05040000 06060200  ................
00002010: 06030707 04040309 02080906 00090503  ................
00002020: 08080701 04000408 05020309 00010901  ................
00002030: 05010704 08060201 06080800 01020304  ................
00002040: 07080900 01020304 06070809 00010203  ................
00002050: 04070809 01040503 03000905 04030008  ................
00002060: 04060700 07070106 09010306 02030802  ................
00002070: 03080905 08080701 07010100 03040206  ................
00002080: 04070402 07040209 02070902 01000605  ................
00002090: 03040805 09060900 06030008 01060000  ................
000020a0: 01020304 05060700 01020304 07080900  ................
000020b0: 01020304 07020501 06040309 09000907  ................
000020c0: 01060403 06020009 08060507 00000107  ................
000020d0: 04030204 01030706 04070707 09080403  ................
000020e0: 08020803 05080005 04070103 01070906  ................
000020f0: 02000901 07030309 01060403 09080201  ................
00002100: 08060401 05050605 00010203 04050607  ................
00002110: 08090001 02030405 06070809 00010203  ................
00002120: 04050607 08090609 07000203 04030805  ................
00002130: 01030001 02010302 00070206 04000509  ................
00002140: 09080905 03010704 07000006 06060307  ................
00002150: 04020809 08070104 00040805 02030900  ................
00002160: 01090105 01070601 02010608 00010203  ................
00002170: 04050607 08090001 02030405 06070800  ................
00002180: 01020305 06070801 00040506 06030404  ................
00002190: 02080100 06040907 02090200 09030309  ................
000021a0: 01050203 01060703 07080400 02040002  ................
000021b0: 04070800 07000609 03020408 06000507  ................
000021c0: 05010008 01060702 09070905 06050206  ................
000021d0: 02080107 05050703 05000101 03080409  ................
000021e0: 04050108 06080900 01020304 05060708  ................
000021f0: 09000102 03040506 07080900 01020304  ................
00002200: 05060708 09030503 02090302 01040505  ................
00002210: 02030201 03090702 01020809 01080807  ................
00002220: 08010000 06070708 07050006 01050704  ................
00002230: 06010205 00070909 00030404 08040108  ................
00002240: 06050900 00000307 01060406 00040504  ................
00002250: 01030806 03090905 09030708 05060407  ................
00002260: 06020200 09040001 02030405 06070809  ................
00002270: 00010203 04050607 08090001 02030405  ................
00002280: 06070809 06040206 04070505 04070209  ................
00002290: 03090308 02000905 06000100 06050305  ................
000022a0: 03080000 03040105 03000803 00060207  ................
000022b0: 08010701 03080504 02000907 06070401  ................
000022c0: 06020607 01090800 06090409 09060203  ................
000022d0: 07010902 02050307 08000102 03040708  ................
000022e0: 09000102 03040708 09000107 08090809  ................
000022f0: 02060103 05040802 06040304 05090200  ................
00002300: 03090409 07030807 04040908 05080206  ................
00002310: 06020301 03020703 01090001 01030500  ................
00002320: 07080105 01040600 00040901 06060900  ................
00002330: 07060101 00010203 04070203 04050607  ................
00002340: 00010207 08060309 07010903 09060107  ................
00002350: 02040405 07000001 06060802 07070204  ................
00002360: 02010601 00060908 03090603 00010203  ................
00002370: 04050607 08090001 02030405 06070809  ................
00002380: 00010203 04050607 08090106 08090900  ................
00002390: 01020404 03070404 04000308 07050802  ................
000023a0: 01070503 08050205 01010602 01030806  ................
000023b0: 04020602 05050002 08000608 01070901  ................
000023c0: 09020607 06060807 04090201 03030005  ................
000023d0: 05080003 07090700 02070901 07080003  ................
000023e0: 05030600 01020304 05060708 09000102  ................
000023f0: 03040506 07080900 01020304 07080906  ................
00002400: 04020604 07080902 09030903 00000100  ................
00002410: 04020603 05030003 04010503 00080300  ................
00002420: 06010708 00090206 07010906 09040909  ................
00002430: 06070102 05030708 00010204 05060708  ................
00002440: 09000103 04050607 08000103 04070809  ................
00002450: 07050501 09090701 00000509 07010702  ................
00002460: 02030608 03020000 06010705 08060209  ................
00002470: 04080807 01000807 07050805 03040601  ................
00002480: 01050500 07020306 04010204 01050402  ................
00002490: 00040806 01090002 05060903 06030600  ................
000024a0: 01020304 05060708 09000102 03040506  ................
000024b0: 07080900 01020305 06070801 00090507  ................
000024c0: 05010806 09000401 09030804 04070001  ................
000024d0: 09020807 08020509 06000605 05030303  ................
000024e0: 09080101 00060100 00060201 01030207  ................
000024f0: 07080807 08040600 02000700 03060807  ................
00002500: 01050909 03070204 09040306 02020503  ................
00002510: 02050509 04010702 00010203 04050607  ................
00002520: 08090001 02030405 06070809 00010203  ................
00002530: 04050607 08090100 01020705 03040400  ................
00002540: 00060906 06050702 03040409 01040007  ................
00002550: 09050702 03010404 00090906 01080303  ................
00002560: 07030908 08040707 06020109 08070808  ................
00002570: 07020203 09030305 05000709 05060501  ................
00002580: 04010102 08020601 05000102 03040506  ................
00002590: 07080900 01020304 05060708 09000102  ................
000025a0: 03040506 07080800 06000002 03070904  ................
000025b0: 07010901 07010400 00010705 07010303  ................
000025c0: 03010609 07010300 02060008 09040305  ................
000025d0: 04080105 09000606 03080104 07050200  ................
000025e0: 00010708 09060808 02030601 02090502  ................
000025f0: 00010203 04050607 08090001 02030405  ................
00002600: 06070809 00010203 04050607 08090704  ................
00002610: 06010400 09090307 08040705 08050302  ................
00002620: 02000508 06000308 01000300 04070409  ................
00002630: 02090507 01070106 06050602 08070604  ................
00002640: 09090503 07040300 04060601 01030201  ................
00002650: 00000102 03040708 09000102 03040506  ................
00002660: 07080001 02030407 08090008 03090505  ................
00002670: 02060804 01070102 03050609 01010102  ................
00002680: 01020007 07050802 09080607 03040608  ................
00002690: 07000402 07070504 03040208 01050100  ................
000026a0: 02030305 07000608 06030909 08020707  ................
000026b0: 01000107 08090001 02030405 06070800  ................
000026c0: 01020304 07080907 08060401 09030804  ................
000026d0: 04070001 09020807 08020600 06050303  ................
000026e0: 03090104 00060100 00060201 01070708  ................
000026f0: 04060007 00030608 07010502 04090403  ................
00002700: 06040107 02060500 01020304 05060708  ................
00002710: 09000102 03040506                    ........
caozilong@caozilong-Vostro-3268:~/ml/dataset/mnist$                 

对于训练集标签train-labels-idx1-ubyte也是如此,只不过个数变成了0xea60=60000个,如下图所示。

说完了标签集,来看图片集,以t10k-images-idx3-ubyte为例,它的内容是:

从头看,0x00000803是魔数,图片都是0x00000803,以区别标签的魔数0x00000801.接着0x00002710=10000=10k,表示图片个数,测试集有10000张数字照片。接着连着两个的0x1c分别表示图片行和列的大小,单位字节,也就是每个图片是28*28大小。存储的时候按行存储。. Pixel values are 0 to 255. 0 means background (white), 255 means foreground (black).

按照这个格式要求,我们计算一下文件大小,看和文件实际大小是否相符.

28*28*10000 + 4*4 = 7840016字节。

我们发现完全符合。

最后是训练集train-images-idx3-ubyte,训练集也是其中最大的,格式和上面介绍的测试图片集完全一样,只有图片个数不同。

它的大小计算公式为:28*28*60000 + 4*4 = 47040016字节

内容:


结束!