標籤:
MNIST是一套對手寫數字進行識別的資料集:http://yann.lecun.com/exdb/mnist/
MNIST的資料結構官網上已給出,挺奇葩的-.-,所以第一件事是把資料整理出來
我寫了個指令碼幫我整理,輸出的是一坨文字檔,
【其中image是用灰階矩陣表示,每個像素1位元組,每張圖28x28 pixels
1 #include <iostream> 2 #include <cstring> 3 #include <cstdio> 4 #include <cstdlib> 5 using namespace std; 6 string st; 7 int tx,ty,ans,nm; 8 9 int toshi(char x)10 {11 int tmp;12 if(x<=‘9‘) tmp=x-‘0‘;13 else tmp=x-‘a‘+10;14 return tmp;15 }16 17 int main() //image18 {19 freopen("testimages.txt","r",stdin);20 21 for (int IM=1;IM<=10010;IM++)22 {23 char fn[50]="";24 itoa(IM,fn,10);25 freopen(fn,"w",stdout);26 nm=0;27 cout<<"[";28 for(int CC=1;CC<=392;CC++) //28*28/229 {30 cin>>st;31 ty=toshi(st[0]);32 tx=toshi(st[1]);33 ans=ty*16+tx;34 if(nm%28==0) cout<<"[";35 nm++;36 cout<<ans;37 if(nm%28!=0) cout<<",";38 if(nm%28==0) if(nm%784==0) cout<<"]"; else cout<<"];";39 40 ty=toshi(st[2]);41 tx=toshi(st[3]);42 ans=ty*16+tx;43 if(nm%28==0) cout<<"[";44 nm++;45 cout<<ans;46 if(nm%28!=0) cout<<",";47 if(nm%28==0) if(nm%784==0) cout<<"]"; else cout<<"];";48 }49 cout<<"]";50 }51 52 53 return 0;54 }55 56 57 58 /*59 int main() //label60 {61 freopen("testlabel.txt","r",stdin);62 //freopen("23333.out","w",stdout);63 64 for (int IM=1;IM<=10000;IM+=2)65 {66 char fn[50]="";67 itoa(IM,fn,10);68 freopen(fn,"w",stdout);69 cin>>st;70 ty=toshi(st[0]);71 tx=toshi(st[1]);72 ans=ty*16+tx;73 cout<<ans<<" ";74 75 itoa(IM+1,fn,10);76 freopen(fn,"w",stdout);77 ty=toshi(st[2]);78 tx=toshi(st[3]);79 ans=ty*16+tx;80 cout<<ans<<" ";81 }82 83 84 return 0;85 }86 87 */View Code
兩個int main()一個是給image用的一個是給label用的,需要時選其中一個,把另一個注釋掉即可。
迴圈變數IM表示資料數量。traindata有60000組,testdata有10000組
[Exercise]用softmax Regression測試MNIST資料集