MNIST手写数字数据库

手写数字库很容易建立,但是总会很浪费时间。Google实验室的Corinna Cortes和纽约大学柯朗研究所的Yann LeCun建有一个手写数字数据库,训练库有60,000张手写数字图像,测试库有10,000张。

请访问原站 http://yann.lecun.com/exdb/mnist/

该数据库在一个文件中包含了所有图像,使用起来有所不便。如果我把每个图像分别保存,成了图像各自独立的数据库。

并在Google Code中托管。

如果你有需要,欢迎在此下载:

http://yann.lecun.com/exdb/mnist/

http://code.google.com/p/supplement-of-the-mnist-database-of-handwritten-digits/downloads/list

Handwritten Digits MNIST Handwritten Digits [data/mnist_all.mat]
[training pictures: 012 3456789 ]
[testing pictures: 01 23 456789 ]
8-bit grayscale images of "0" through "9"; about 6K training examples of each class; 1K test examples USPS Handwritten Digits [data/usps_all.mat]
[pictures: 0123456789 ]
8-bit grayscale images of "0" through "9"; 1100 examples of each class. Binary Alphadigits [data/binaryalphadigs.mat] [picture]
Binary 20x16 digits of "0" through "9" and capital "A" through "Z". 39 examples of each class.
From Simon Lucas‘ ([email protected]), Algoval system.

另有提供matlab读取的MNIST、USPS、Binary Alphadigits数据库,Data for MATLAB hackers,见:http://www.cs.toronto.edu/~roweis/data.html

参考网址:
[1] http://yann.lecun.com/exdb/mnist/
[2] http://hi.baidu.com/ln0707/blog/item/8207ef010a243d81d53f7c03.html
[3] http://www.cs.toronto.edu/~roweis/data.html

[4] http://blog.csdn.net/onezeros/archive/2010/05/28/5631930.aspx

如何使用MNIST数据集:

MNIST是一个据说很出名的手写数字数据库,据说是美国中学生手写的数字,说实话大部分都写得挺丑的。。。Anyway,幸好能看得懂是哪个数字。现在课题是用CNN(卷积神经网络)识别这个数据库的数字。我想,CNN还真没懂,不过先搞清楚怎么读入数据库吧,不然空有理论无法实操。一般人会用MATLAB来做神经网络的东东,而我正是一个一般人。当然,非一般的人可能用python之类的高端平台,反正我是不会。。。

首先上搜索引擎,无论是百度还是google,搜“MNIST”第一个出来的肯定是

http://yann.lecun.com/exdb/mnist/ 没错,就是它!这个网页上面有四个压缩包的链接,下载下来吧少年!然后别忙着关掉这个网页,因为后面的读取数据还得依靠这个网页的说明。

下面用其中一个包t10k-images_idx3为例子,写代码说明如何使用这个数据库。

这是从verysource.com上面下载的源码,赞一个!and再赞一个!

% Matlab_Read_t10k-images_idx3.m

% 用于读取MNIST数据集中t10k-images.idx3-ubyte文件并将其转换成bmp格式图片输出。

% 用法:运行程序,会弹出选择测试图片数据文件t10k-labels.idx1-ubyte路径的对话框和

% 选择保存测试图片路径的对话框,选择路径后程序自动运行完毕,期间进度条会显示处理进度。

% 图片以TestImage_00001.bmp~TestImage_10000.bmp的格式保存在指定路径,10000个文件占用空间39M。。

% 整个程序运行过程需几分钟时间。

% Written By [email protected] IPRAI

% 2009-2-22

clear all;

clc;

%读取训练图片数据文件

[FileName,PathName] = uigetfile(‘*.*‘,‘选择测试图片数据文件t10k-images.idx3-ubyte‘);

TrainFile = fullfile(PathName,FileName);

fid = fopen(TrainFile,‘r‘); %fopen()是最核心的函数,导入文件,‘r’代表读入

a = fread(fid,16,‘uint8‘); %这里需要说明的是,包的前十六位是说明信息,从上面提到的那个网页可以看到具体那一位代表什么意义。所以a变量提取出这些信息,并记录下来,方便后面的建立矩阵等动作。

MagicNum = ((a(1)*256+a(2))*256+a(3))*256+a(4);

ImageNum = ((a(5)*256+a(6))*256+a(7))*256+a(8);

ImageRow = ((a(9)*256+a(10))*256+a(11))*256+a(12);

ImageCol = ((a(13)*256+a(14))*256+a(15))*256+a(16);

%从上面提到的网页可以理解这四句,给出了数据集的大小

if ((MagicNum~=2051)||(ImageNum~=10000))

error(‘不是 MNIST t10k-images.idx3-ubyte 文件!‘);

fclose(fid);

return;

end %排除选择错误的文件。

savedirectory = uigetdir(‘‘,‘选择测试图片路径:‘);

h_w = waitbar(0,‘请稍候,处理中>>‘);

for i=1:ImageNum

b = fread(fid,ImageRow*ImageCol,‘uint8‘);   %fread()也是核心的函数之一,b记录下了一副图的数据串。注意这里还是个串,是看不出任何端倪的。

c = reshape(b,[ImageRow ImageCol]); %亮点来了,reshape重新构成矩阵,终于把串转化过来了。众所周知图片就是矩阵,这里reshape出来的灰度矩阵就是该手写数字的矩阵了。

d = c‘; %转置一下,因为c的数字是横着的。。。

e = 255-d; %根据灰度理论,0是黑色,255是白色,为了弄成白底黑字就加入了e

e = uint8(e);

savepath = fullfile(savedirectory,[‘TestImage_‘ num2str(i,d) ‘.bmp‘]);

imwrite(e,savepath,‘bmp‘); %最后用imwrite写出图片

waitbar(i/ImageNum);

end

fclose(fid);

close(h_w);

在选择好的路径中,就有了一大堆MNIST的手写数字的图片。想弄哪个,就用imread()弄它!

时间: 2024-08-03 14:45:02

MNIST手写数字数据库的相关文章

Tensorflow实践 mnist手写数字识别

minst数据集                                         tensorflow的文档中就自带了mnist手写数字识别的例子,是一个很经典也比较简单的入门tensorflow的例子,非常值得自己动手亲自实践一下.由于我用的不是tensorflow中自带的mnist数据集,而是从kaggle的网站下载下来的,数据集有些不太一样,所以直接按照tensorflow官方文档上的参数训练的话还是踩了一些坑,特此记录. 首先从kaggle网站下载mnist数据集,一份是

tensorflow 基础学习五:MNIST手写数字识别

MNIST数据集介绍: from tensorflow.examples.tutorials.mnist import input_data # 载入MNIST数据集,如果指定地址下没有已经下载好的数据,tensorflow会自动下载数据 mnist=input_data.read_data_sets('.',one_hot=True) # 打印 Training data size:55000. print("Training data size: {}".format(mnist.

基于MNIST手写数字数据集的数字识别小程序

30行代码奉上!(MNIST手写数字的识别,识别率大约在91%,简单尝试的一个程序,小玩具而已) 1 import tensorflow.examples.tutorials.mnist.input_data as input_data 2 import tensorflow as tf 3 mnist = input_data.read_data_sets('/temp/', one_hot=True) 4 5 #设置 6 x = tf.placeholder(tf.float32,[None

Pytorch入门实战一:LeNet神经网络实现 MNIST手写数字识别

记得第一次接触手写数字识别数据集还在学习TensorFlow,各种sess.run(),头都绕晕了.自从接触pytorch以来,一直想写点什么.曾经在2017年5月,Andrej Karpathy发表的一片Twitter,调侃道:l've been using PyTorch a few months now, l've never felt better, l've more energy.My skin is clearer. My eye sight has improved.确实,使用p

简单HOG+SVM mnist手写数字分类

使用工具 :VS2013 + OpenCV 3.1 数据集:minst 训练数据:60000张 测试数据:10000张 输出模型:HOG_SVM_DATA.xml 数据准备 train-images-idx3-ubyte.gz:  training set images (9912422 bytes) train-labels-idx1-ubyte.gz:  training set labels (28881 bytes) t10k-images-idx3-ubyte.gz:   test s

MNIST手写数字分类simple版(03-2)

simple版本nn模型 训练手写数字处理 import tensorflow as tf from tensorflow.examples.tutorials.mnist import input_data #载入数据集 mnist=input_data.read_data_sets("MNIST_data", one_hot=True) #每个批次的大小 batch_size=100 #计算一共有多少批次 n_batch=mnist.train.num_examples // ba

MNIST手写数字图片识别(线性回归、CNN方法的手工及框架实现)(未完待续)

0-Background 作为Deep Learning中的Hello World 项目无论如何都要做一遍的. 代码地址:Github 练习过程中将持续更新blog及代码. 第一次写博客,很多地方可能语言组织不清,请多多提出意见..谢谢~ 0.1 背景知识: Linear regression CNN LeNet-5 AlexNet ResNet VGG 各种regularization方式 0.2 Catalog 1-Prepare 2-MNIST 3-LinearRegression 1-P

Tensorflow之MNIST手写数字识别:分类问题(2)

整体代码: #数据读取 import tensorflow as tf import matplotlib.pyplot as plt import numpy as np from tensorflow.examples.tutorials.mnist import input_data mnist = input_data.read_data_sets("MNIST_data/",one_hot=True) #定义待输入数据的占位符 #mnist中每张照片共有28*28=784个像

Caffe 例子使用记录(一)mnist手写数字识别

1. 安装caffe请参考 http://www.cnblogs.com/xuanyuyt/p/5726926.html 2. 下载训练和测试数据.caffe识别leveldb或者lmdb格式的数据,这里提供转换好的LEVELDB格式数据集,解压缩到mnist例子目录下 链接:http://pan.baidu.com/s/1gfjXteV 密码:45j6 3. 打开lenet_solver.prototxt,这里可以自己试着改几个参数看看最终效果 # The train/test net pro