資源簡介
MNIST數據庫處理-matlab生成mnist_uint8.mat。
功能:將下載得到的二進制文件轉換為10進制數據,提取像素數據和標簽數據
適用:僅適用于MNIST數據集,修改后可適用于其他
功能:將下載得到的二進制文件轉換為10進制數據,提取像素數據和標簽數據
適用:僅適用于MNIST數據集,修改后可適用于其他

代碼片段和文件信息
%MNIST源文件下載地址http://yann.lecun.com/exdb/mnist/index.html
%功能:將下載得到的二進制文件轉換為10進制數據,提取像素數據和標簽數據
%適用:僅適用于MNIST數據集,修改后可適用于其他
%Create?by?VivienFu?e-mail:vivienfu@163.com
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
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2019-12-29?13:43??MNIST?to?uint8?by?matlab\
?????文件????????3011??2017-01-01?22:41??MNIST?to?uint8?by?matlab\decodefile.m
?????文件????????1275??2017-01-01?22:41??MNIST?to?uint8?by?matlab\mnist_uint8.m
評論
共有 條評論