TensorFlow官方教程学习笔记(四)——MNIST数据集的读取

转载自:https://www.2cto.com/kf/201701/587638.html


MNIST的images文件:

TRAINING SET IMAGE FILE (train-images-idx3-ubyte):
offsettypevaluedescription
000032 bit integer0x00000803(2051)magic number
000432 bit integer60000number of images
000832 bit integer28number of rows
001232 bit integer28number of columns
0016unsigned byte??pixel
0017unsigned byte??pixel
0018unsigned byte??pixel
......   
xxxxunsigned byte??pixel

代码中_read32()的定义在第33行,作用是从文件流中动态读取4位数据并转换为uint32的数据。

image文件的前四位为魔术码(magic number),只有检测到这4位数据的值和2051相等时,才代表这是正确的image文件,才会继续往下读取。接下来继续读取之后的4位,代表着image文件中,所包含的图片的数量(num_images)。再接着读4位,为每一幅图片的行数(rows),再后4位,为每一幅图片的列数(cols)。最后再读接下来的rows * cols * num_images位,即为所有图片的像素值。最后再将读取到的所有像素值装换为[index, rows, cols, depth]的4D矩阵。这样就将全部的image数据读取了出来。

同理,对于MNIST的labels文件:

TRAINING SET LABEL FILE (train-labels-idx1-ubyte):
offsettypevaluedescription
000032 bit integer0x00000801(2049)magic number
000432 bit integer60000number of items
0008unsigned byte??label
0009unsigned byte??label
......   
xxxxunsigned byte??label

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值