【求助】本地加载fashion-mnist数据集,利用frombuffer读取时为什么需要offset=16与offset=8

由于使用tensorflow.keras时加载fashion-mnist数据集都要在线下载,因此选择加载本地已经下载好的.gz格式的数据集,如图所示
在这里插入图片描述
加载数据集的程序如下:
其中注释行不太理解,gzip解压后,使用numpy.frombuffer读入时,为什么需要设置读取样本时的offset=16,读取标签时的offset=8?

def get_data():
	x_train_path = r"F:/Data/fashion_minist/train-images-idx3-ubyte.gz"
	y_train_path = r"F:/Data/fashion_minist/train-labels-idx1-ubyte.gz"
	x_test_path = r"F:/Data/fashion_minist/t10k-images-idx3-ubyte.gz"
	y_test_path = r"F:/Data/fashion_minist/t10k-labels-idx1-ubyte.gz"
	with gzip.open(x_train_path, "rb") as data:
    	x_train = np.frombuffer(data.read(), np.uint8, offset=16).reshape(-1, 28, 28)  # 有疑问处!
	with gzip.open(y_train_path, "rb") as data:
    	y_train = np.frombuffer(data.read(), np.uint8, offset=8)  # 有疑问处!
	with gzip.open(x_test_path, "rb") as data:
    	x_test = np.frombuffer(data.read(), np.uint8, offset=16).reshape(-1, 28, 28)  # 有疑问处!
	with gzip.open(y_test_path, "rb") as data:
    	y_test = np.frombuffer(data.read(), np.uint8, offset=8)  # 有疑问处!    
	return (x_train, y_train), (x_test, y_test) 
  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值