通过MATLAB读取mnist数据库
mnist (手寫字符識別) 的數據集下載地:
http://yann.lecun.com/exdb/mnist/
MNIST是在機器學習領域中的一個經典問題。該問題解決的是把28x28像素的灰度手寫數字圖片識別為相應的數字,其中數字的范圍從0到9.下載后得到四個文件:
train-images-idx3-ubyte.gz,訓練集,共 60,000 幅(28*28)的圖像數據;
train-labels-idx1-ubyte.gz,訓練集的標簽信息(取值為 0-9),60,000*1
t10k-images-idx3-ubyte.gz,測試集(t: test, 10k: 10,000),共 10,000 副(28*28)的圖像數據
t10k-labels-idx1-ubyte.gz,測試集的標簽呢信息(取值為 0-9),10,000*1
通過如下的MATLAB可以讀取四個文件:
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)';
運行后,可以看到:
?可以看到60000個訓練數據,10000個測試數據。
總結
以上是生活随笔為你收集整理的通过MATLAB读取mnist数据库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于MATLAB的车牌定位和识别
- 下一篇: 在Hammerstein非线性模型中,基