通过MATLAB读取mnist数据库
mnist (手寫字符識(shí)別) 的數(shù)據(jù)集下載地:
http://yann.lecun.com/exdb/mnist/
MNIST是在機(jī)器學(xué)習(xí)領(lǐng)域中的一個(gè)經(jīng)典問題。該問題解決的是把28x28像素的灰度手寫數(shù)字圖片識(shí)別為相應(yīng)的數(shù)字,其中數(shù)字的范圍從0到9.下載后得到四個(gè)文件:
train-images-idx3-ubyte.gz,訓(xùn)練集,共 60,000 幅(28*28)的圖像數(shù)據(jù);
train-labels-idx1-ubyte.gz,訓(xùn)練集的標(biāo)簽信息(取值為 0-9),60,000*1
t10k-images-idx3-ubyte.gz,測試集(t: test, 10k: 10,000),共 10,000 副(28*28)的圖像數(shù)據(jù)
t10k-labels-idx1-ubyte.gz,測試集的標(biāo)簽?zāi)匦畔?#xff08;取值為 0-9),10,000*1
通過如下的MATLAB可以讀取四個(gè)文件:
fid = fopen('train-labels.idx1-ubyte', 'rb');
trainLabels = fread(fid, inf, 'uint8', 'l');
trainLabels = trainLabels(9:end);
fclose(fid);
% read test labels
fid = fopen('t10k-labels.idx1-ubyte', 'rb');
testLabels = fread(fid, inf, 'uint8', 'l');
testLabels = testLabels(9:end);
fclose(fid);
% read train images
fid = fopen('train-images.idx3-ubyte', 'rb');
trainImages = fread(fid, inf, 'uint8', 'l');
trainImages = trainImages(17:end);
fclose(fid);
trainData = reshape(trainImages, 784, size(trainImages,1) / 784)';
% read train images
fid = fopen('t10k-images.idx3-ubyte', 'rb');
testImages = fread(fid, inf, 'uint8', 'l');
testImages = testImages(17:end);
fclose(fid);
testData = reshape(testImages, 784, size(testImages,1) / 784)';
運(yùn)行后,可以看到:
?可以看到60000個(gè)訓(xùn)練數(shù)據(jù),10000個(gè)測試數(shù)據(jù)。
總結(jié)
以上是生活随笔為你收集整理的通过MATLAB读取mnist数据库的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于MATLAB的车牌定位和识别
- 下一篇: 在Hammerstein非线性模型中,基