參考:https://jingyan.baidu.com/article/656db9183296c7e381249cf4.html
1、使用讀取方式pickle
def unpickle(file):
import pickle
with open(file, 'rb') as fo:
dict = pickle.load(fo, encoding='bytes')
return dict
返回的是一個python字典
2、通過字典的內置函數,獲取鍵值
>>> dict.keys()
dict_keys([b'labels', b'batch_label', b'data', b'filenames'])
3、打印所有鍵值對應的值
>>> dict[b'labels']------------------對應的是每個圖片的真實結果Y,通過batches.meta可以找出對應的字符結果,比如:0表示‘airplane’
[6, 9, 9, 4, 1, 1, 2, 7, 8, 3, 4, 7, 7, 2, 9, 9, 9, 3, ............. 9, 1, 1, 5](結果省略了一些)
>>> len(dict[b'labels'])-----------代表圖片的結果數量確實為10000
10000
>>> dict[b'batch_label']------------對應當前數據集是訓練集中的那一份
b'training batch 1 of 5'
>>> dict[b'filenames']---------------對應數據集中每張圖片的文件名
[b'leptodactylus_pentadactylus_s_000004.png', b'camion_s_000148.png', b'tipper_truck_s_001250.png', b'american_elk_s_001521.png',......... b'estate_car_s_001433.png', b'cur_s_000170.png'](結果同樣省略了一些)
>>> dict[b'data']----------------每張圖片的數據,每一位類型為uint8
array([[ 59, 43, 50, ..., 140, 84, 72],
[154, 126, 105, ..., 139, 142, 144],
[255, 253, 253, ..., 83, 83, 84],
...,
[ 71, 60, 74, ..., 68, 69, 68],
[250, 254, 211, ..., 215, 255, 254],
[ 62, 61, 60, ..., 130, 130, 131]], dtype=uint8)
>>> dict[b'data'].shape----------由於我們需要用圖像數據來進行卷積,所以需要知道shape
(10000, 3072)(代表有10000張圖片,每張圖片3072b大小(32 x 32 x 3),前1024是Red通道的圖片data,接着是Green通道的1024圖片,之后是Blue通道的1024圖片)