資源簡介
自己用java代碼寫的識別手寫數字的全連接的神經網絡
代碼片段和文件信息
import?java.io.File;
import?java.io.FileNotFoundException;
import?java.io.FileOutputStream;
import?java.io.IOException;
import?java.util.ArrayList;
import?java.util.List;
public?class?DeepLearn3Test?{
static?List?trains?=?null?;
static?List?tests?=?null;
public?static?void?main(String[]?args)?{
//load?mnist
ReadFile?rf1=new?ReadFile(“train-labels.idx1-ubyte““train-images.idx3-ubyte“);
ReadFile?rf2=new?ReadFile(“t10k-labels.idx1-ubyte““t10k-images.idx3-ubyte“);
try?{
tests?=?rf2.loadDigitImages();
trains?=rf1.loadDigitImages();
}?catch?(IOException?e)?{
//?TODO?Auto-generated?catch?block
e.printStackTrace();
}
int?size[]={784402010};
NeuralNetwork?network?=?new?NeuralNetwork(size);
network.radomInitWandB();
double?image[]?=?new?double[784];
for(int?kk=0;kk<10;kk++){
//first:?set?input
for(int?count=0;count for(int?i=0;i<784;i++){
image[i]?=?(int)(trains.get(count).imageData[i]&0xff);
}
network.setInput(image);
//second:?forward?cal?output
double[]?output?=?network.forwardProc();
//third:?backward?cal?delta
double[]?y?=?new?double[10];
for(int?i=0;i if(i==trains.get(count).label){
y[i]?=?1;
}else{
y[i]?=?0;
}
}
network.backwarkProc(y);
//fouth:?update?w?and?b
network.updateWAndB(0.5);
}
System.out.println(“finished?train?count:?“+kk);
}
boolean?isTest?=?true;
//test
if(isTest){
int?countCorrect=0;
for(int?count=0;count for(int?i=0;i<784;i++){
image[i]?=?(int)(tests.get(count).imageData[i]&0xff);
}
network.setInput(image);
//second:?forward?cal?output
int?number?=?network.testDigitalImage();
if(number==tests.get(count).label)countCorrect++;
//System.out.println(“count?is?:?“+count+“??number?is:?“+number+“??label?is:??“+tests.get(count).label);
}
System.out.println(“countCorrect:?“+countCorrect);
}
}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2017-05-19?19:51??DeepLearn3Test\
?????文件?????????301??2017-05-19?09:18??DeepLearn3Test\.classpath
?????目錄???????????0??2017-05-20?16:45??DeepLearn3Test\.git\
?????文件??????????25??2017-05-20?16:44??DeepLearn3Test\.git\COMMIT_EDITMSG
?????文件?????????370??2017-05-20?16:45??DeepLearn3Test\.git\config
?????文件??????????73??2017-05-19?16:36??DeepLearn3Test\.git\desc
?????文件??????????23??2017-05-19?16:36??DeepLearn3Test\.git\HEAD
?????目錄???????????0??2017-05-19?16:36??DeepLearn3Test\.git\hooks\
?????文件?????????478??2017-05-19?16:36??DeepLearn3Test\.git\hooks\applypatch-msg.sample
?????文件?????????896??2017-05-19?16:36??DeepLearn3Test\.git\hooks\commit-msg.sample
?????文件?????????189??2017-05-19?16:36??DeepLearn3Test\.git\hooks\post-update.sample
?????文件?????????424??2017-05-19?16:36??DeepLearn3Test\.git\hooks\pre-applypatch.sample
?????文件????????1642??2017-05-19?16:36??DeepLearn3Test\.git\hooks\pre-commit.sample
?????文件????????1348??2017-05-19?16:36??DeepLearn3Test\.git\hooks\pre-push.sample
?????文件????????4951??2017-05-19?16:36??DeepLearn3Test\.git\hooks\pre-reba
?????文件?????????544??2017-05-19?16:36??DeepLearn3Test\.git\hooks\pre-receive.sample
?????文件????????1239??2017-05-19?16:36??DeepLearn3Test\.git\hooks\prepare-commit-msg.sample
?????文件????????3610??2017-05-19?16:36??DeepLearn3Test\.git\hooks\update.sample
?????文件????????2309??2017-05-20?16:44??DeepLearn3Test\.git\index
?????目錄???????????0??2017-05-19?16:36??DeepLearn3Test\.git\info\
?????文件?????????240??2017-05-19?16:36??DeepLearn3Test\.git\info\exclude
?????目錄???????????0??2017-05-19?16:40??DeepLearn3Test\.git\logs\
?????文件?????????476??2017-05-20?16:44??DeepLearn3Test\.git\logs\HEAD
?????目錄???????????0??2017-05-19?16:41??DeepLearn3Test\.git\logs\refs\
?????目錄???????????0??2017-05-19?16:40??DeepLearn3Test\.git\logs\refs\heads\
?????文件?????????476??2017-05-20?16:44??DeepLearn3Test\.git\logs\refs\heads\master
?????目錄???????????0??2017-05-19?16:41??DeepLearn3Test\.git\logs\refs\remotes\
?????目錄???????????0??2017-05-19?16:41??DeepLearn3Test\.git\logs\refs\remotes\origin\
?????文件?????????435??2017-05-20?16:45??DeepLearn3Test\.git\logs\refs\remotes\origin\master
?????目錄???????????0??2017-05-20?16:44??DeepLearn3Test\.git\ob
?????目錄???????????0??2017-05-20?16:44??DeepLearn3Test\.git\ob
............此處省略112個文件信息
評論
共有 條評論