
image数据集是二进制存储,前32个字节是4个int,分别表示magic(没啥用?), num(图片个数), rows(图像行数), cols(列)。之后每个字节就是图像的每个像素。
labels数据集第前16个字节是2个int, 分别表示magic,, num,后面每个字节表示图像的数字,对应images里的每个图片
解析minst的方式很多,用python简单的实现以下
# -*-coding:utf8-*-
import numpy as np
import struct
import cv2
# 读取minist数据集,image, label读读取方式不同
def load_minist(path, kind="image"):
""""
:param path: 文件的路径
:param kind: 读取文件的种类,分为image, label
:return:
"""
if kind == 'image':
with open(path, mode='rb') as img_read:
magic, num, row, col = struct.unpack('>IIII', img_read.read(16))
images = np.fromfile(img_read, dtype=np.uint8).reshape(-1, row*col)
return images
if kind == 'label':
with open(path, 'rb') as label_read:
magic, num = struct.unpack('<

本文介绍MNIST数据集的二进制存储结构,包括图像数据集的魔法数、图片数量、行数和列数信息,以及标签数据集的魔法数和数字标签。内容探讨了如何使用Python简单解析MNIST数据。
2万+

被折叠的 条评论
为什么被折叠?



