(小白必看)Keras手写数字识别模型:下载的数据集需要格式转换才能使用

1.下载附件

如果你嫌用代码自动下载太慢,而且时不时会挂,可以选下面两个方案之一下载

方案一:我提供的百度网盘

链接: https://pan.baidu.com/s/1dEGabct 密码: gmvs

方案二:通过官网下载,还嫌慢可以用迅雷

官网下载数据集合:http://yann.lecun.com/exdb/mnist/

下载mnist.npz:https://s3.amazonaws.com/img-datasets/mnist.npz (亚马逊被墙了建议用迅雷)

mnist.npz直接放入~/.keras/datasets/

train-labels-idx1-ubyte.gz训练标签数据,放入项目的根目录下即可

train-images-idx3-ubyte.gz训练标签数据,放入项目的根目录下即可

t10k-labels-idx1-ubyte.gz训练标签数据,放入项目的根目录下即可

t10k-images-idx3-ubyte.gz训练标签数据,放入项目的根目录下即可

2.格式转换

自己手动下载的附件是不能直接用的,要转换成bmp图片格式。官网最底部有对数据集合的详细说明和IDX文件格式的解析规则,感兴趣的可以自己写代码转换。另外附上monitor1379大神的转换代码

转换代码:转换代码原文链接

把大神的链接放在模型代码前即可,注意修改下数据集的路径

(小白必看)Keras手写数字识别模型:下载的数据集需要格式转换才能使用_第1张图片
引号中把文件名前的都去掉就行了

官网说明:

FILE FORMATS FOR THE MNIST DATABASE

The data is stored in a very simple file format designed for storing vectors and multidimensional matrices. General info on this format is given at the end of this page, but you don't need to read that to use the data files.

All the integers in the files are stored in the MSB first (high endian) format used by most non-Intel processors. Users of Intel processors and other low-endian machines must flip the bytes of the header.

There are 4 files:

train-images-idx3-ubyte: training set images

train-labels-idx1-ubyte: training set labels

t10k-images-idx3-ubyte:  test set images

t10k-labels-idx1-ubyte:  test set labels

The training set contains 60000 examples, and the test set 10000 examples.

The first 5000 examples of the test set are taken from the original NIST training set. The last 5000 are taken from the original NIST test set. The first 5000 are cleaner and easier than the last 5000.

TRAINING SET LABEL FILE (train-labels-idx1-ubyte):

[offset] [type]          [value]          [description]

0000     32 bit integer  0x00000801(2049) magic number (MSB first)

0004     32 bit integer  60000            number of items

0008     unsigned byte   ??               label

0009     unsigned byte   ??               label

........

xxxx     unsigned byte   ??               label

The labels values are 0 to 9.

TRAINING SET IMAGE FILE (train-images-idx3-ubyte):

[offset] [type]          [value]          [description]

0000     32 bit integer  0x00000803(2051) magic number

0004     32 bit integer  60000            number of images

0008     32 bit integer  28               number of rows

0012     32 bit integer  28               number of columns

0016     unsigned byte   ??               pixel

0017     unsigned byte   ??               pixel

........

xxxx     unsigned byte   ??               pixel

Pixels are organized row-wise. Pixel values are 0 to 255. 0 means background (white), 255 means foreground (black).

TEST SET LABEL FILE (t10k-labels-idx1-ubyte):

[offset] [type]          [value]          [description]

0000     32 bit integer  0x00000801(2049) magic number (MSB first)

0004     32 bit integer  10000            number of items

0008     unsigned byte   ??               label

0009     unsigned byte   ??               label

........

xxxx     unsigned byte   ??               label

The labels values are 0 to 9.

TEST SET IMAGE FILE (t10k-images-idx3-ubyte):

[offset] [type]          [value]          [description]

0000     32 bit integer  0x00000803(2051) magic number

0004     32 bit integer  10000            number of images

0008     32 bit integer  28               number of rows

0012     32 bit integer  28               number of columns

0016     unsigned byte   ??               pixel

0017     unsigned byte   ??               pixel

........

xxxx     unsigned byte   ??               pixel

Pixels are organized row-wise. Pixel values are 0 to 255. 0 means background (white), 255 means foreground (black).

THE IDX FILE FORMAT

the IDX file format is a simple format for vectors and multidimensional matrices of various numerical types.

The basic format is

magic number

size in dimension 0

size in dimension 1

size in dimension 2

.....

size in dimension N

data

The magic number is an integer (MSB first). The first 2 bytes are always 0.

The third byte codes the type of the data:

0x08: unsigned byte

0x09: signed byte

0x0B: short (2 bytes)

0x0C: int (4 bytes)

0x0D: float (4 bytes)

0x0E: double (8 bytes)

The 4-th byte codes the number of dimensions of the vector/matrix: 1 for vectors, 2 for matrices....

The sizes in each dimension are 4-byte integers (MSB first, high endian, like in most non-Intel processors).

The data is stored like in a C array, i.e. the index in the last dimension changes the fastest.

你可能感兴趣的:((小白必看)Keras手写数字识别模型:下载的数据集需要格式转换才能使用)