資源簡介
包含原始數據及mnist_uint8.mat文件的生成代碼,可以直接運行生成.mat文件
代碼片段和文件信息
%MNIST源文件下載地址http://yann.lecun.com/exdb/mnist/index.html
%功能:將下載得到的二進制文件轉換為10進制數據,提取像素數據和標簽數據
%適用:僅適用于MNIST數據集,修改后可適用于其他
?
function?output=decodefile(filenametype)
%數據介紹如下,參考網址http://yann.lecun.com/exdb/mnist/index.html
?
%?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
?
%?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
fio=fopen(filename‘r‘);%原始文件中數據是以2進制存儲的。
a?=?fread(fio‘uint8‘);%以8進制方式讀取源文件。雖然前幾項是32bit的,但是圖像像素數據是8bit的,所以此處用8bit處理。
?
if?strcmp(type‘image‘)
%?????magic_num=a(1)*256^3+a(2)*256^2+a(3)*256+a(4);
%?????image_num=a(5)*256^3+a(6)*256^2+a(7)*256+a(8);
%?????image_rows=a(9)*256^3+a(10)*256^2+a(11)*256+a(12);%默認訓練和測試圖像都已經reshape到一個size
%?????image_cols=a(13)*256^3+a(14)*256^2+a(15)*256+a(16);
?
????output=a(17:end);%提取像素數據
else?if?strcmp(type‘label‘)
%?????????magic_num=a(1)*256^3+a(2)*256^2+a(3)*256+a(4);
%?????????image_num=a(5)*256^3+a(6)*256^2+a(7)*256+a(8);
????????output=a(9:end);??????
????end
end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????2973??2018-11-15?10:38??mnist_dataset\decodefile.m
?????文件???????1236??2018-11-15?10:35??mnist_dataset\mnist_uint8.m
?????文件???11847358??2018-11-15?10:39??mnist_dataset\mnist_uint8.mat
?????文件????7840016??1998-01-26?23:07??mnist_dataset\t10k-images.idx3-ubyte
?????文件??????10008??1998-01-26?23:07??mnist_dataset\t10k-labels.idx1-ubyte
?????文件???47040016??1996-11-18?23:36??mnist_dataset\train-images.idx3-ubyte
?????文件??????60008??1996-11-18?23:36??mnist_dataset\train-labels.idx1-ubyte
?????目錄??????????0??2018-11-15?10:39??mnist_dataset
-----------?---------??----------?-----??----
?????????????66801615????????????????????8
評論
共有 條評論