[Exercise]用softmax Regression測試MNIST資料集

來源:互聯網
上載者:User

標籤:

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資料集

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.